//----------------------------------------------------------------------------- IFontPainter* CFontDesc::getFontPainter () { IPlatformFont* pf = getPlatformFont (); if (pf) return pf->getPainter (); return 0; }
//------------------------------------------------------------------------ void CDrawContext::drawString (IPlatformString* string, const CRect& _rect, const CHoriTxtAlign hAlign, bool antialias) { if (!string || currentState.font == 0) return; IFontPainter* painter = currentState.font->getFontPainter (); if (painter == 0) return; CRect rect (_rect); double capHeight = -1; IPlatformFont* platformFont = currentState.font->getPlatformFont (); if (platformFont) capHeight = platformFont->getCapHeight (); if (capHeight > 0.) rect.bottom -= (rect.getHeight () / 2. - capHeight / 2.); else rect.bottom -= (rect.getHeight () / 2. - currentState.font->getSize () / 2.) + 1.; if (hAlign != kLeftText) { CCoord stringWidth = painter->getStringWidth (this, string, antialias); if (hAlign == kRightText) rect.left = rect.right - stringWidth; else rect.left = rect.left + (rect.getWidth () / 2.) - (stringWidth / 2.); } painter->drawString (this, string, CPoint (rect.left, rect.bottom), antialias); }
/// @cond ignore //------------------------------------------------------------------------ static CCoord getFontCapHeight (CFontRef font) { CCoord c = font->getSize (); IPlatformFont* pf = font->getPlatformFont (); if (pf) { CCoord capHeight = pf->getCapHeight (); if (capHeight <= 0) capHeight = pf->getAscent (); if (capHeight > 0) c = capHeight; } return c; }
//----------------------------------------------------------------------------- void CDrawContext::drawString (UTF8StringPtr _string, const CRect& _rect, const CHoriTxtAlign hAlign, bool antialias) { if (!_string || currentState.font == 0) return; IFontPainter* painter = currentState.font->getFontPainter (); if (painter == 0) return; const CString& string = getDrawString (_string); CRect rect (_rect); double capHeight = -1; IPlatformFont* platformFont = currentState.font->getPlatformFont (); if (platformFont) capHeight = platformFont->getCapHeight (); if (capHeight > 0.) rect.bottom -= (rect.height ()/2 - capHeight / 2); else rect.bottom -= (rect.height ()/2 - currentState.font->getSize () / 2) + 1; if (hAlign != kLeftText) { CCoord stringWidth = painter->getStringWidth (this, string, antialias); if (hAlign == kRightText) rect.left = rect.right - stringWidth; else rect.left = (CCoord)(rect.left + (rect.getWidth () / 2.f) - (stringWidth / 2.f)); } CRect oldClip; getClipRect (oldClip); CRect newClip (_rect); newClip.bound (oldClip); setClipRect (newClip); painter->drawString (this, string, CPoint (rect.left, rect.bottom), antialias); setClipRect (oldClip); clearDrawString (); }