Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

font_metrics Namespace Reference

A namespace holding helper functions for determining the screen dimensions of fonts. More...


Functions

int maxAscent (LyXFont const &f)
 return the maximum ascent of the font. More...

int maxDescent (LyXFont const &f)
 return the maximum descent of the font. More...

int ascent (char c, LyXFont const &f)
 return the ascent of the char in the font. More...

int descent (char c, LyXFont const &f)
 return the descent of the char in the font. More...

int lbearing (char c, LyXFont const &f)
 return the left bearing of the char in the font. More...

int rbearing (char c, LyXFont const &f)
 return the right bearing of the char in the font. More...

int width (char const *s, size_t n, LyXFont const &f)
 return the width of the string in the font. More...

int width (char c, LyXFont const &f)
 return the width of the char in the font. More...

int width (string const &s, LyXFont const &f)
 return the width of the string in the font. More...

int signedWidth (string const &s, LyXFont const &f)
 FIXME ?? More...

void rectText (string const &str, LyXFont const &font, int &width, int &ascent, int &descent)
 fill in width,ascent,descent with the values for the given string in the font. More...

void buttonText (string const &str, LyXFont const &font, int &width, int &ascent, int &descent)
 fill in width,ascent,descent with the values for the given string in the font for a button. More...

Encoding const * fontencoding (LyXFont const &f)
int smallcapswidth (char const *s, size_t ls, LyXFont const &f)


Detailed Description

A namespace holding helper functions for determining the screen dimensions of fonts.

The geometry is the standard typographical geometry, as follows :

--------------+------------------<maxAscent | | <-------> (right bearing) <-> (left bearing) char ascent>___ | ^ oooo | oooo origin>____ | oo oo | oo oo \| oo oo | oo oo --------------+---ooooo--|--oooo-<baseline | oo | char | oo oo | descent>______| oooo | <- width -> --------------+----------+-------<maxDescent


Function Documentation

int font_metrics::ascent char    c,
LyXFont const &    f
 

return the ascent of the char in the font.

Definition at line 63 of file qfont_metrics.C.

Referenced by Painter::buttonText, MathXYArrowInset::draw, MathNestInset::draw, MathFracInset::draw, MathBinomInset::draw, InsetSpecialChar::draw, InsetSpace::draw, InsetLatexAccent::draw, MathSqrtInset::drawT, MathFracInset::drawT, getFontID, mathed_char_ascent, mathed_char_dim, MathRootInset::metrics, MathMacroTemplate::metrics, MathDelimInset::metrics, MathBraceInset::metrics, InsetLatexAccent::metrics, RowPainter::paintFirst, RowPainter::paintLast, Painter::rectText, setAscentFractions, LyXText::setHeightOfRow, and LyXScreen::showCursor.

00064 {
00065         if (!lyx_gui::use_gui)
00066                 return 1;
00067         QRect const & r = metrics(f).boundingRect(c);
00068         return -r.top();
00069 }

void font_metrics::buttonText string const &    str,
LyXFont const &    font,
int &    width,
int &    ascent,
int &    descent
 

fill in width,ascent,descent with the values for the given string in the font for a button.

Definition at line 187 of file qfont_metrics.C.

Referenced by Painter::buttonText, InsetCollapsable::dimension_collapsed, getFontID, InsetCollapsable::height_collapsed, and ButtonRenderer::metrics.

00191 {
00192         QFontMetrics const & m(metrics(f));
00193 
00194         static int const d = 3;
00195 
00196         w = width(str, f) + d * 2 + 2;
00197         ascent = m.ascent() + d;
00198         descent = m.descent() + d;
00199 }

int font_metrics::descent char    c,
LyXFont const &    f
 

return the descent of the char in the font.

Definition at line 72 of file qfont_metrics.C.

Referenced by Painter::buttonText, MathXYArrowInset::draw, MathRootInset::draw, MathFracInset::draw, MathBinomInset::draw, MathSqrtInset::drawT, MathFracInset::drawT, getFontID, mathed_char_descent, mathed_char_dim, MathRootInset::metrics, MathMacroTemplate::metrics, MathDelimInset::metrics, MathBraceInset::metrics, InsetLatexAccent::metrics, Painter::rectText, setAscentFractions, and LyXScreen::showCursor.

00073 {
00074         if (!lyx_gui::use_gui)
00075                 return 1;
00076         QRect const & r = metrics(f).boundingRect(c);
00077         return r.bottom()+1;
00078 }

Encoding const* fontencoding LyXFont const &    f
 

Definition at line 100 of file qfont_metrics.C.

00101 {
00102         Encoding const * encoding = f.language()->encoding();
00103         if (f.isSymbolFont())
00104                 encoding = encodings.symbol_encoding();
00105         return encoding;
00106 }

int font_metrics::lbearing char    c,
LyXFont const &    f
 

return the left bearing of the char in the font.

Definition at line 81 of file qfont_metrics.C.

Referenced by getFontID, and InsetLatexAccent::lbearing.

00082 {
00083         if (!lyx_gui::use_gui)
00084                 return 1;
00085         return metrics(f).leftBearing(c);
00086 }

int font_metrics::maxAscent LyXFont const &    f
 

return the maximum ascent of the font.

Definition at line 45 of file qfont_metrics.C.

Referenced by Dimension::clear, InsetNewline::draw, InsetText::fitInsetCursor, InsetTabular::fitInsetCursor, getFontID, math_font_max_dim, mathed_string_dim, InsetSpecialChar::metrics, InsetSpace::metrics, InsetQuotes::metrics, InsetNewline::metrics, InsetLatexAccent::metrics, LyXText::setHeightOfRow, and LyXScreen::showCursor.

00046 {
00047         if (!lyx_gui::use_gui)
00048                 return 1;
00049         return metrics(f).ascent();
00050 }

int font_metrics::maxDescent LyXFont const &    f
 

return the maximum descent of the font.

Definition at line 53 of file qfont_metrics.C.

Referenced by Dimension::clear, InsetLatexAccent::draw, InsetText::fitInsetCursor, InsetTabular::fitInsetCursor, getFontID, math_font_max_dim, mathed_string_dim, InsetSpecialChar::metrics, InsetSpace::metrics, InsetQuotes::metrics, InsetNewline::metrics, InsetLatexAccent::metrics, LyXText::setHeightOfRow, and LyXScreen::showCursor.

00054 {
00055         if (!lyx_gui::use_gui)
00056                 return 1;
00057         // We add 1 as the value returned by QT is different than X
00058         // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
00059         return metrics(f).descent() + 1;
00060 }

int font_metrics::rbearing char    c,
LyXFont const &    f
 

return the right bearing of the char in the font.

Definition at line 89 of file qfont_metrics.C.

Referenced by getFontID, and InsetLatexAccent::rbearing.

00090 {
00091         if (!lyx_gui::use_gui)
00092                 return 1;
00093         QFontMetrics const & m(metrics(f));
00094 
00095         // Qt rbearing is from the right edge of the char's width().
00096         return (m.width(c) - m.rightBearing(c));
00097 }

void font_metrics::rectText string const &    str,
LyXFont const &    font,
int &    width,
int &    ascent,
int &    descent
 

fill in width,ascent,descent with the values for the given string in the font.

Definition at line 171 of file qfont_metrics.C.

Referenced by getFontID, ButtonRenderer::metrics, RowPainter::paintAppendixStart, RowPainter::paintLengthMarker, RowPainter::paintPageBreak, and Painter::rectText.

00175 {
00176         QFontMetrics const & m(metrics(f));
00177 
00178         static int const d = 2;
00179 
00180         w = width(str, f) + d * 2 + 2;
00181         ascent = m.ascent() + d;
00182         descent = m.descent() + d;
00183 }

int font_metrics::signedWidth string const &    s,
LyXFont const &    f
 

FIXME ??

Definition at line 162 of file qfont_metrics.C.

Referenced by getFontID, LyXText::leftMargin, and LyXText::rightMargin.

00163 {
00164         if (s[0] == '-')
00165                 return -width(s.substr(1, s.length() - 1), f);
00166         else
00167                 return width(s, f);
00168 }

int smallcapswidth char const *    s,
size_t    ls,
LyXFont const &    f
 

Definition at line 109 of file qfont_metrics.C.

00110 {
00111         if (!lyx_gui::use_gui)
00112                 return 1;
00113         // handle small caps ourselves ...
00114 
00115         LyXFont smallfont(f);
00116         smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
00117 
00118         QFontMetrics const & qm = fontloader.metrics(f);
00119         QFontMetrics const & qsmallm = fontloader.metrics(smallfont);
00120 
00121         Encoding const * encoding(fontencoding(f));
00122 
00123         int w = 0;
00124 
00125         for (size_t i = 0; i < ls; ++i) {
00126                 QChar const c = QChar(encoding->ucs(s[i]));
00127                 QChar const uc = c.upper();
00128                 if (c != uc)
00129                         w += qsmallm.width(uc);
00130                 else
00131                         w += qm.width(c);
00132         }
00133         return w;
00134 }

int width string const &    s,
LyXFont const &    f
[inline]
 

return the width of the string in the font.

Definition at line 63 of file font_metrics.h.

00063                                                               {
00064                 if (s.empty()) return 0;
00065                 return width(s.data(), s.length(), f);
00066         }

int width char    c,
LyXFont const &    f
[inline]
 

return the width of the char in the font.

Definition at line 59 of file font_metrics.h.

00059                                                     {
00060                 return width(&c, 1, f);
00061         }

int font_metrics::width char const *    s,
size_t    n,
LyXFont const &    f
 

return the width of the string in the font.

Definition at line 137 of file qfont_metrics.C.

Referenced by bibitemWidest, InsetSpecialChar::draw, InsetQuotes::draw, InsetNewline::draw, InsetCaption::draw, LyXText::fill, LyXText::getColumnNearX, LyXText::getCursorX, getFontID, LyXText::labelFill, LyXText::leftMargin, mathed_char_width, mathed_string_dim, mathed_string_width, GraphicRenderer::metrics, MathCharInset::metrics, InsetSpecialChar::metrics, InsetSpace::metrics, InsetQuotes::metrics, InsetNewline::metrics, InsetLatexAccent::metrics, InsetFormulaMacro::metrics, RowPainter::paintArabicComposeChar, RowPainter::paintChars, RowPainter::paintFirst, RowPainter::paintHebrewComposeChar, RowPainter::paintLast, RowPainter::paintSelection, RowPainter::paintText, LyXText::prepareToPrint, LyXText::rowBreakPoint, and LyXText::singleWidth.

00138 {
00139         if (!lyx_gui::use_gui)
00140                 return ls;
00141 
00142         if (f.realShape() == LyXFont::SMALLCAPS_SHAPE) {
00143                 return smallcapswidth(s, ls, f);
00144         }
00145 
00146         Encoding const * encoding(fontencoding(f));
00147 
00148         if (ls == 1) {
00149                 return charwidth(encoding->ucs(s[0]), f);
00150         }
00151 
00152         int w = 0;
00153 
00154         for (size_t i = 0; i < ls; ++i) {
00155                 w += charwidth(encoding->ucs(s[i]), f);
00156         }
00157 
00158         return w;
00159 }


Generated on Fri Jul 18 01:19:06 2003 for lyx by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002