Ejemplo n.º 1
0
double Font::drawString( const char *inString, doublePair inPosition,
                         TextAlignment inAlign ) {
    double scale = scaleFactor * mScaleFactor;
    
    unsigned int numChars = strlen( inString );
    
    double x = inPosition.x;
    
    // compensate for extra headspace in accent-equipped font files
    double y = inPosition.y + scale * mSpriteHeight / 4;
    
    double stringWidth = 0;
    
    if( inAlign != alignLeft ) {
        stringWidth = measureString( inString );
        }
    
    switch( inAlign ) {
        case alignCenter:
            x -= stringWidth / 2;
            break;
        case alignRight:
            x -= stringWidth;
            break;
        default:
            // left?  do nothing
            break;            
        }
    
    // character sprites are drawn on their centers, so the alignment
    // adjustments above aren't quite right.
    x += scale * mSpriteWidth / 2;
    

    for( unsigned int i=0; i<numChars; i++ ) {
        doublePair charPos = { x, y };
        
        double charWidth = drawCharacter( (unsigned char)( inString[i] ), 
                                          charPos );
        x += charWidth + mCharSpacing * scale;
        }
    // no spacing after last character
    x -= mCharSpacing * scale;

    return x;
    }
Ejemplo n.º 2
0
void GR_Graphics::getMaxCharacterDimension(const UT_UCSChar*s, UT_uint32 length, UT_uint32 &width, UT_uint32 &height)
{
	UT_GrowBufElement *pWidths = new UT_GrowBufElement[length];


	UT_uint32 maxHeight = 0;
	measureString(s, 0, length, pWidths, &maxHeight);

	UT_sint32 maxWidth = 0;

	for(UT_uint32 i = 0; i < length; i++)
	{
		if(pWidths[i] > maxWidth)
			maxWidth = pWidths[i];
	}

	DELETEPV(pWidths);

	width = maxWidth;
	if (maxHeight > 0) { 
		height = maxHeight;
	}
}
Ejemplo n.º 3
0
void GR_Graphics::measureRenderedCharWidths(GR_RenderInfo & ri) 
{
	UT_return_if_fail(ri.getType() == GRRI_XP);
	GR_XPRenderInfo & RI = (GR_XPRenderInfo &) ri;
	UT_return_if_fail(RI.m_pWidths);
	
	//bool bReverse = (RI.m_iVisDir == UT_BIDI_RTL);

	UT_sint32 i;

	for (i = 0; i < RI.m_iLength; i++)
	{
		if(i > 0 && *(RI.m_pChars + i) == UCS_LIGATURE_PLACEHOLDER)
		{
			RI.m_pWidths[i]   = RI.m_pWidths[i - 1]/2;
			UT_uint32 mod     = RI.m_pWidths[i-1]%2;
			RI.m_pWidths[i-1] = RI.m_pWidths[i] + mod;
		}
		else
		{

			measureString(RI.m_pChars + i, 0, 1,
					 static_cast<UT_GrowBufElement*>(RI.m_pWidths) + i);
		}
	}

	if(RI.isJustified())
	{
		justify(RI);
	}
	
	// make sure that we invalidate the static buffers if we own them
	if(RI.s_pOwner == &RI)
		RI.s_pOwner = NULL;
	
}
Ejemplo n.º 4
0
/**
* CBitmapFont::drawStringView
* @date Modified Apr 04, 2006
*/
void CBitmapFont::drawStringView(CString str, RECT rView, unsigned int unOffset, D3DCOLOR dwColor, bool bHandleSprite)
{
	std::vector<CString> vLines, vWords, vColors;
	unsigned int unWidth = rView.right - rView.left,
				 unHeight = rView.bottom - rView.top,
				 unWordWidth = 0;
	RECT rWord;
	float fX = (float)rView.left, fY = (float)rView.top;
	str.ToList(vLines, "\r\n");

	if(bHandleSprite)
		beginSprite();

	// Calculate max number of lines
	unsigned int unLineCount = unHeight / m_cLineHeight;

	// Iterate lines in string.
	size_t i = ((vLines.size() <= unLineCount) ? 0 : max(vLines.size() - unOffset - unLineCount, 0));
	for(; i < ((vLines.size() <= unLineCount) ? vLines.size() : vLines.size() - unOffset); ++i)
	{
		// Iterate words in string.
		vLines[i].ToList(vWords, " ");
		for(size_t j = 0; j < vWords.size(); ++j)
		{
			bool bFirst = false;
			vWords[j].ToList(vColors, "{}");
			if(vWords[j].GetChar(0) == '{')
				bFirst = true;
				
			if(vColors.size())
			{
				for(size_t k = 0; k < vColors.size(); ++k)
				{
					if((bFirst && k % 2 == 0) || (!bFirst && k % 2 == 1))
					{
						dwColor = vColors[k].ToUlongFromHex();
						continue;						   
					}

					// Take line length into consideration
					unWordWidth = measureString(vColors[k], &rWord);
					if(fX + unWordWidth >= unWidth)
					{
						fX = (float)rView.left;
						fY += m_cLineHeight;
						drawString(vColors[k], fX, fY, dwColor, false);
					}
					else
					{
						drawString(vColors[k], fX, fY, dwColor, false);
						fX += unWordWidth + m_mCharMap[' '];
					}
				}
				
			}
			else
			{
				// Take line length into consideration
				unWordWidth = measureString(vWords[j], &rWord);
				if(fX + unWordWidth >= unWidth)
				{
					fX = (float)rView.left;
					fY += m_cLineHeight;
					drawString(vWords[j], fX, fY, dwColor, false);
				}
				else
				{
					drawString(vWords[j], fX, fY, dwColor, false);
					fX += unWordWidth + m_mCharMap[' '];
				}
			}
		}
		fX = (float)rView.left;
		fY += m_cLineHeight;
	}

	if(bHandleSprite)
		endSprite();
}
Ejemplo n.º 5
0
void WLPaint::measurePropString(const char *string, quint16 *width, quint16 *height)
{
    measureString(string, width, height, (fontstruct *)wlcache->graphic(STARTFONT + fontnumber));
}
Ejemplo n.º 6
0
/**
Displays Menu on the screen as overlay on top of another Perspective view
*/
void Menu::display()
{
  if (isDisplayed)
  {
    glDisable(GL_LIGHTING);
	  glDepthMask(GL_FALSE);
	  glDisable(GL_DEPTH_TEST);
	  glViewport(0, 0, window->getSize().x, window->getSize().y);

    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0f, window->getSize().x, window->getSize().y, 0.0f, -1000.f, 10000.0f);

    glMatrixMode(GL_MODELVIEW);

    // Draw background box with border around complete menu
    buttonBox(menuPosition, menuSize, colorBackDefault, 1000);

    unsigned counter = 0; // button counter

    // Draw box with border for each visible menu button
    for(unsigned i = 0; i < menuItems.size(); i++)
    {
      if (menuItems.at(i)._topMenuName == itemActivated)
      {
        // Draw button
        buttonBox(
          sf::Vector2f(menuPosition.x, menuButtonSize.y * counter + menuPosition.y), 
          menuButtonSize, 
          menuItems.at(i).colorDefaultBack,
          i
        );

        // Add text to the button
        std::string text = menuItems.at(i).text;
        sf::Vector2i textSize = measureString(text, hFontMenu);

        textToScreen(
          hFontMenu, 
          charListMenu, 
          sf::Vector3f(
            menuPosition.x + (menuButtonSize.x - textSize.x) / 2, 
            menuPosition.y + menuButtonSize.y * (counter + 1) / 2 + textSize.y * counter, 
            200.0f), 
          colorTextDefault,
          "%s", text.c_str()
        );

        // Icnrement button counter
        counter++;
      }
    }

    //# Item Activated will tell which menus need to be displayed i.e. display all submenus who's container is itemActivated

    // # Iterate over map items and display items for top name menu
    // # if itemActivated != topName iterate over map items and display items under the top name menu
    // # if itemActivated != any item under topName keep displaying sub items under these menus until reached itemActivated

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glFlush();

	  glLineWidth(2);
	  glDepthMask(GL_TRUE);
	  glEnable(GL_DEPTH_TEST);
	  glEnable(GL_LIGHTING);
  }
}
Ejemplo n.º 7
0
gfx::Size Graphics::drawStringAlgorithm(const std::string& str, Color fg, Color bg, const gfx::Rect& rc, int align, bool draw)
{
  gfx::Point pt(0, rc.y);

  if ((align & (JI_MIDDLE | JI_BOTTOM)) != 0) {
    gfx::Size preSize = drawStringAlgorithm(str, ColorNone, ColorNone, rc, 0, false);
    if (align & JI_MIDDLE)
      pt.y = rc.y + rc.h/2 - preSize.h/2;
    else if (align & JI_BOTTOM)
      pt.y = rc.y + rc.h - preSize.h;
  }

  gfx::Size calculatedSize(0, 0);
  size_t beg, end, new_word_beg, old_end;
  std::string line;

  // Draw line-by-line
  for (beg=end=0; end != std::string::npos; ) {
    pt.x = rc.x;

    // Without word-wrap
    if ((align & JI_WORDWRAP) == 0) {
      end = str.find('\n', beg);
    }
    // With word-wrap
    else {
      old_end = std::string::npos;
      for (new_word_beg=beg;;) {
        end = str.find_first_of(" \n", new_word_beg);

        // If we have already a word to print (old_end != npos), and
        // we are out of the available width (rc.w) using the new "end",
        if ((old_end != std::string::npos) &&
            (pt.x+measureString(str.substr(beg, end-beg)).w > rc.w)) {
          // We go back to the "old_end" and paint from "beg" to "end"
          end = old_end;
          break;
        }
        // If we have more words to print...
        else if (end != std::string::npos) {
          // Force line break, now we have to paint from "beg" to "end"
          if (str[end] == '\n')
            break;

          // White-space, this is a beginning of a new word.
          new_word_beg = end+1;
        }
        // We are in the end of text
        else
          break;

        old_end = end;
      }
    }

    // Get the entire line to be painted
    line = str.substr(beg, end-beg);

    gfx::Size lineSize = measureString(line);
    calculatedSize.w = MAX(calculatedSize.w, lineSize.w);

    // Render the text
    if (draw) {
      int xout;
      if ((align & JI_CENTER) == JI_CENTER)
        xout = pt.x + rc.w/2 - lineSize.w/2;
      else if ((align & JI_RIGHT) == JI_RIGHT)
        xout = pt.x + rc.w - lineSize.w;
      else
        xout = pt.x;

      ji_font_set_aa_mode(m_currentFont, to_system(bg));
      textout_ex(m_bmp, m_currentFont, line.c_str(), m_dx+xout, m_dy+pt.y, to_system(fg), to_system(bg));

      if (!is_transparent(bg))
        fillAreaBetweenRects(bg,
          gfx::Rect(rc.x, pt.y, rc.w, lineSize.h),
          gfx::Rect(xout, pt.y, lineSize.w, lineSize.h));
    }

    pt.y += lineSize.h;
    calculatedSize.h += lineSize.h;
    beg = end+1;
  }

  // Fill bottom area
  if (draw && !is_transparent(bg)) {
    if (pt.y < rc.y+rc.h)
      fillRect(bg, gfx::Rect(rc.x, pt.y, rc.w, rc.y+rc.h-pt.y));
  }

  return calculatedSize;
}