1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
15 #pragma implementation "lyxfont.h"
25 #include "FontLoader.h"
26 #include "support/lstrings.h"
29 // The global fontloader
30 FontLoader fontloader;
36 string const GUIFamilyNames[6] =
37 { N_("Roman"), N_("Sans serif"), N_("Typewriter"), N_("Symbol"), N_("Inherit"),
40 string const GUISeriesNames[4] =
41 { N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") };
43 string const GUIShapeNames[6] =
44 { N_("Upright"), N_("Italic"), N_("Slanted"), N_("Smallcaps"), N_("Inherit"),
47 string const GUISizeNames[14] =
48 { N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"),
49 N_("Larger"), N_("Largest"), N_("Huge"), N_("Huger"), N_("Increase"), N_("Decrease"),
50 N_("Inherit"), N_("Ignore") };
52 string const lGUISizeNames[15] =
53 { N_("tiny"), N_("smallest"), N_("smaller"), N_("small"), N_("normal"), N_("large"),
54 N_("larger"), N_("largest"), N_("huge"), N_("huger"), N_("increase"), N_("decrease"),
55 N_("inherit"), N_("ignore"), string() };
57 string const GUIMiscNames[5] =
58 { N_("Off"), N_("On"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
60 string const GUIDirectionNames[5] =
61 { N_("LTR"), N_("RTL"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
65 // Strings used to read and write .lyx format files
67 string const LyXFamilyNames[6] =
68 { "roman", "sans", "typewriter", "symbol", "default", "error" };
70 string const LyXSeriesNames[4] =
71 { "medium", "bold", "default", "error" };
73 string const LyXShapeNames[6] =
74 { "up", "italic", "slanted", "smallcaps", "default", "error" };
76 string const LyXSizeNames[14] =
77 { "tiny", "scriptsize", "footnotesize", "small", "normal", "large",
78 "larger", "largest", "huge", "giant",
79 "increase-error", "decrease-error", "default", "error" };
81 string const LyXMiscNames[12] =
82 { "off", "on", "toggle", "default", "error" };
85 // Strings used to write LaTeX files
88 string const LaTeXFamilyNames[6] =
89 { "textrm", "textsf", "texttt", "error1", "error2", "error3" };
91 string const LaTeXSeriesNames[4] =
92 { "textmd", "textbf", "error4", "error5" };
94 string const LaTeXShapeNames[6] =
95 { "textup", "textit", "textsl", "textsc", "error6", "error7" };
97 string const LaTeXSizeNames[14] =
98 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
99 "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
102 LyXFont::FontBits LyXFont::sane = {
114 LyXFont::FontBits LyXFont::inherit = {
126 LyXFont::FontBits LyXFont::ignore = {
139 /// Decreases font size by one
140 LyXFont & LyXFont::decSize()
143 case SIZE_HUGER: setSize(SIZE_HUGE); break;
144 case SIZE_HUGE: setSize(SIZE_LARGEST); break;
145 case SIZE_LARGEST: setSize(SIZE_LARGER); break;
146 case SIZE_LARGER: setSize(SIZE_LARGE); break;
147 case SIZE_LARGE: setSize(SIZE_NORMAL); break;
148 case SIZE_NORMAL: setSize(SIZE_SMALL); break;
149 case SIZE_SMALL: setSize(SIZE_FOOTNOTE); break;
150 case SIZE_FOOTNOTE: setSize(SIZE_SCRIPT); break;
151 case SIZE_SCRIPT: setSize(SIZE_TINY); break;
152 case SIZE_TINY: break;
154 lyxerr << "Can't LyXFont::decSize on INCREASE_SIZE" << endl;
157 lyxerr <<"Can't LyXFont::decSize on DECREASE_SIZE" << endl;
160 lyxerr <<"Can't LyXFont::decSize on INHERIT_SIZE" << endl;
163 lyxerr <<"Can't LyXFont::decSize on IGNORE_SIZE" << endl;
170 /// Increases font size by one
171 LyXFont & LyXFont::incSize()
174 case SIZE_HUGER: break;
175 case SIZE_HUGE: setSize(SIZE_HUGER); break;
176 case SIZE_LARGEST: setSize(SIZE_HUGE); break;
177 case SIZE_LARGER: setSize(SIZE_LARGEST); break;
178 case SIZE_LARGE: setSize(SIZE_LARGER); break;
179 case SIZE_NORMAL: setSize(SIZE_LARGE); break;
180 case SIZE_SMALL: setSize(SIZE_NORMAL); break;
181 case SIZE_FOOTNOTE: setSize(SIZE_SMALL); break;
182 case SIZE_SCRIPT: setSize(SIZE_FOOTNOTE); break;
183 case SIZE_TINY: setSize(SIZE_SCRIPT); break;
185 lyxerr <<"Can't LyXFont::incSize on INCREASE_SIZE" << endl;
188 lyxerr <<"Can't LyXFont::incSize on DECREASE_SIZE" << endl;
191 lyxerr <<"Can't LyXFont::incSize on INHERIT_SIZE" << endl;
194 lyxerr <<"Can't LyXFont::incSize on IGNORE_SIZE" << endl;
201 /// Updates a misc setting according to request
202 LyXFont::FONT_MISC_STATE LyXFont::setMisc(FONT_MISC_STATE newfont,
205 if (newfont == TOGGLE) {
211 lyxerr <<"LyXFont::setMisc: Need state"
212 " ON or OFF to toggle. Setting to ON" << endl;
215 } else if (newfont == IGNORE)
222 /// Updates font settings according to request
223 void LyXFont::update(LyXFont const & newfont, bool toggleall)
225 if(newfont.family() == family() && toggleall)
226 setFamily(INHERIT_FAMILY); // toggle 'back'
227 else if (newfont.family() != IGNORE_FAMILY)
228 setFamily(newfont.family());
229 // else it's IGNORE_SHAPE
231 // "Old" behaviour: "Setting" bold will toggle bold on/off.
232 switch (newfont.series()) {
235 if (series() == BOLD_SERIES && toggleall)
236 setSeries(MEDIUM_SERIES);
238 setSeries(BOLD_SERIES);
242 setSeries(newfont.series());
248 if(newfont.shape() == shape() && toggleall)
249 setShape(INHERIT_SHAPE); // toggle 'back'
250 else if (newfont.shape() != IGNORE_SHAPE)
251 setShape(newfont.shape());
252 // else it's IGNORE_SHAPE
254 if (newfont.size() != IGNORE_SIZE) {
255 if (newfont.size() == INCREASE_SIZE)
257 else if (newfont.size() == DECREASE_SIZE)
259 else if (newfont.size() == size() && toggleall)
260 setSize(INHERIT_SIZE); // toggle 'back'
262 setSize(newfont.size());
265 setEmph(setMisc(newfont.emph(), emph()));
266 setUnderbar(setMisc(newfont.underbar(), underbar()));
267 setNoun(setMisc(newfont.noun(), noun()));
268 setLatex(setMisc(newfont.latex(), latex()));
270 switch(newfont.direction()) {
272 if (direction() == LTR_DIR)
273 setDirection(RTL_DIR);
275 setDirection(LTR_DIR);
280 setDirection(newfont.direction());
283 if(newfont.color() == color() && toggleall)
284 setColor(LColor::inherit); // toggle 'back'
285 else if (newfont.color() != LColor::ignore)
286 setColor(newfont.color());
290 /// Reduce font to fall back to template where possible
291 void LyXFont::reduce(LyXFont const & tmplt)
293 if (family() == tmplt.family())
294 setFamily(INHERIT_FAMILY);
295 if (series() == tmplt.series())
296 setSeries(INHERIT_SERIES);
297 if (shape() == tmplt.shape())
298 setShape(INHERIT_SHAPE);
299 if (size() == tmplt.size())
300 setSize(INHERIT_SIZE);
301 if (emph() == tmplt.emph())
303 if (underbar() == tmplt.underbar())
304 setUnderbar(INHERIT);
305 if (noun() == tmplt.noun())
307 if (latex() == tmplt.latex())
309 if (color() == tmplt.color())
310 setColor(LColor::inherit);
311 if (direction() == tmplt.direction())
312 setDirection(INHERIT_DIR);
316 /// Realize font from a template
317 LyXFont & LyXFont::realize(LyXFont const & tmplt)
319 if (bits == inherit) {
324 if (bits.family == INHERIT_FAMILY) {
325 bits.family = tmplt.bits.family;
327 if (bits.series == INHERIT_SERIES) {
328 bits.series = tmplt.bits.series;
330 if (bits.shape == INHERIT_SHAPE) {
331 bits.shape = tmplt.bits.shape;
333 if (bits.size == INHERIT_SIZE) {
334 bits.size = tmplt.bits.size;
336 if (bits.emph == INHERIT) {
337 bits.emph = tmplt.bits.emph;
339 if (bits.underbar == INHERIT) {
340 bits.underbar = tmplt.bits.underbar;
342 if (bits.noun == INHERIT) {
343 bits.noun = tmplt.bits.noun;
345 if (bits.latex == INHERIT) {
346 bits.latex = tmplt.bits.latex;
348 if (bits.color == LColor::inherit) {
349 bits.color = tmplt.bits.color;
351 if (bits.direction == INHERIT_DIR) {
352 bits.direction = tmplt.bits.direction;
359 /// Is font resolved?
360 bool LyXFont::resolved() const
362 return (family() != INHERIT_FAMILY && series() != INHERIT_SERIES &&
363 shape() != INHERIT_SHAPE && size() != INHERIT_SIZE &&
364 emph() != INHERIT && underbar() != INHERIT &&
365 noun() != INHERIT && latex() != INHERIT &&
366 color() != LColor::inherit &&
367 direction() != INHERIT_DIR);
371 /// Build GUI description of font state
372 string LyXFont::stateText() const
375 if (family() != INHERIT_FAMILY)
376 buf += string(_(GUIFamilyNames[family()].c_str())) + ", ";
377 if (series() != INHERIT_SERIES)
378 buf += string(_(GUISeriesNames[series()].c_str())) + ", ";
379 if (shape() != INHERIT_SHAPE)
380 buf += string(_(GUIShapeNames[shape()].c_str())) + ", ";
381 if (size() != INHERIT_SIZE)
382 buf += string(_(GUISizeNames[size()].c_str())) + ", ";
383 if (color() != LColor::inherit)
384 buf += lcolor.getGUIName(color()) + ", ";
385 if (emph() != INHERIT)
386 buf += string(_("Emphasis ")) + _(GUIMiscNames[emph()].c_str()) + ", ";
387 if (underbar() != INHERIT)
388 buf += string(_("Underline ")) + _(GUIMiscNames[underbar()].c_str()) + ", ";
389 if (noun() != INHERIT)
390 buf += string(_("Noun ")) + _(GUIMiscNames[noun()].c_str()) + ", ";
391 if (latex() != INHERIT)
392 buf += string(_("Latex ")) + _(GUIMiscNames[latex()].c_str()) + ", ";
393 if (direction() != INHERIT_DIR)
394 buf += string(_("Direction ")) + _(GUIDirectionNames[direction()].c_str()) + ", ";
397 buf = strip(buf, ' ');
398 buf = strip(buf, ',');
403 // Set family according to lyx format string
404 LyXFont & LyXFont::setLyXFamily(string const & fam)
406 string s = lowercase(fam);
409 while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") ++i;
410 if (s == LyXFamilyNames[i]) {
411 setFamily(LyXFont::FONT_FAMILY(i));
413 lyxerr << "LyXFont::setLyXFamily: Unknown family `"
414 << s << '\'' << endl;
419 // Set series according to lyx format string
420 LyXFont & LyXFont::setLyXSeries(string const & ser)
422 string s = lowercase(ser);
425 while (s != LyXSeriesNames[i] && LyXSeriesNames[i] != "error") ++i;
426 if (s == LyXSeriesNames[i]) {
427 setSeries(LyXFont::FONT_SERIES(i));
429 lyxerr << "LyXFont::setLyXSeries: Unknown series `"
430 << s << '\'' << endl;
435 // Set shape according to lyx format string
436 LyXFont & LyXFont::setLyXShape(string const & sha)
438 string s = lowercase(sha);
441 while (s != LyXShapeNames[i] && LyXShapeNames[i] != "error") ++i;
442 if (s == LyXShapeNames[i]) {
443 setShape(LyXFont::FONT_SHAPE(i));
445 lyxerr << "LyXFont::setLyXShape: Unknown shape `"
446 << s << '\'' << endl;
451 // Set size according to lyx format string
452 LyXFont & LyXFont::setLyXSize(string const & siz)
454 string s = lowercase(siz);
456 while (s != LyXSizeNames[i] && LyXSizeNames[i] != "error") ++i;
457 if (s == LyXSizeNames[i]) {
458 setSize(LyXFont::FONT_SIZE(i));
460 lyxerr << "LyXFont::setLyXSize: Unknown size `"
461 << s << '\'' << endl;
465 // Set size according to lyx format string
466 LyXFont::FONT_MISC_STATE LyXFont::setLyXMisc(string const & siz)
468 string s = lowercase(siz);
470 while (s != LyXMiscNames[i] && LyXMiscNames[i] != "error") ++i;
471 if (s == LyXMiscNames[i])
472 return FONT_MISC_STATE(i);
473 lyxerr << "LyXFont::setLyXMisc: Unknown misc flag `"
474 << s << '\'' << endl;
478 /// Sets color after LyX text format
479 LyXFont & LyXFont::setLyXColor(string const & col)
481 setColor(lcolor.getFromLyXName(col));
486 /// Sets size after GUI name
487 LyXFont & LyXFont::setGUISize(string const & siz)
489 #warning this might be wrong.
491 // this is how it was how it was done in the lyx repository...
492 // but this does not make sense.
493 setColor(lcolor.getFromGUIName(siz));
498 // Returns size in latex format
499 string LyXFont::latexSize() const
501 return LaTeXSizeNames[size()];
505 // Read a font definition from given file in lyx format
507 LyXFont & LyXFont::lyxRead(LyXLex & lex)
510 bool finished = false;
511 while (!finished && lex.IsOK() && !error) {
513 string tok = lowercase(lex.GetString());
517 } else if (tok == "endfont") {
519 } else if (tok == "family") {
521 string tok = lex.GetString();
523 } else if (tok == "series") {
525 string tok = lex.GetString();
527 } else if (tok == "shape") {
529 string tok = lex.GetString();
531 } else if (tok == "size") {
533 string tok = lex.GetString();
535 } else if (tok == "latex") {
537 string tok = lowercase(lex.GetString());
539 if (tok == "no_latex") {
541 } else if (tok == "latex") {
544 lex.printError("Illegal LaTeX type`$$Token'");
546 } else if (tok == "misc") {
548 string tok = lowercase(lex.GetString());
550 if (tok == "no_bar") {
552 } else if (tok == "no_emph") {
554 } else if (tok == "no_noun") {
556 } else if (tok == "emph") {
558 } else if (tok == "underbar") {
560 } else if (tok == "noun") {
563 lex.printError("Illegal misc type `$$Token´");
565 } else if (tok == "color") {
567 string tok = lex.GetString();
569 } else if (tok == "direction") {
571 string tok = lowercase(lex.GetString());
574 setDirection(LTR_DIR);
575 } else if (tok == "rtl") {
576 setDirection(RTL_DIR);
578 lex.printError("Illegal type`$$Token'");
581 lex.printError("Unknown tag `$$Token'");
589 /// Writes the changes from this font to orgfont in .lyx format in file
590 void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const
593 if (orgfont.family() != family()) {
594 os << "\\family " << LyXFamilyNames[family()] << " \n";
596 if (orgfont.series() != series()) {
597 os << "\\series " << LyXSeriesNames[series()] << " \n";
599 if (orgfont.shape() != shape()) {
600 os << "\\shape " << LyXShapeNames[shape()] << " \n";
602 if (orgfont.size() != size()) {
603 os << "\\size " << LyXSizeNames[size()] << " \n";
605 if (orgfont.emph() != emph()) {
606 os << "\\emph " << LyXMiscNames[emph()] << " \n";
608 if (orgfont.underbar() != underbar()) {
609 // This is only for backwards compatibility
610 switch (underbar()) {
611 case OFF: os << "\\bar no \n"; break;
612 case ON: os << "\\bar under \n"; break;
613 case TOGGLE: lyxerr << "LyXFont::lyxWriteFontChanges: "
614 "TOGGLE should not appear here!"
617 case INHERIT: os << "\\bar default \n"; break;
618 case IGNORE: lyxerr << "LyXFont::lyxWriteFontChanges: "
619 "IGNORE should not appear here!"
624 if (orgfont.noun() != noun()) {
625 os << "\\noun " << LyXMiscNames[noun()] << " \n";
627 if (orgfont.latex() != latex()) {
628 // This is only for backwards compatibility
630 case OFF: os << "\\latex no_latex \n"; break;
631 case ON: os << "\\latex latex \n"; break;
632 case TOGGLE: lyxerr << "LyXFont::lyxWriteFontChanges: "
633 "TOGGLE should not appear here!"
636 case INHERIT: os << "\\latex default \n"; break;
637 case IGNORE: lyxerr << "LyXFont::lyxWriteFontChanges: "
638 "IGNORE should not appear here!"
643 if (orgfont.color() != color()) {
644 os << "\\color " << lcolor.getLyXName(color()) << "\n";
646 if (orgfont.direction() != direction()) {
647 switch (direction()) {
648 case RTL_DIR: os << "\\direction rtl \n"; break;
649 case LTR_DIR: os << "\\direction ltr\n"; break;
650 case TOGGLE_DIR: lyxerr << "LyXFont::lyxWriteFontChanges: "
651 "TOGGLE should not appear here!"
653 case INHERIT_DIR: os << "\\direction default \n"; break;
654 case IGNORE_DIR: lyxerr << "LyXFont::lyxWriteFontChanges: "
655 "IGNORE should not appear here!"
663 /// Writes the head of the LaTeX needed to impose this font
664 // Returns number of chars written.
665 int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base,
666 LyXFont const & prev) const
671 if (f.bits == inherit)
677 FONT_DIRECTION direction = f.direction();
678 if (direction != prev.direction()) {
679 if (direction == LTR_DIR) {
682 env = true; //We have opened a new environment
684 if (direction == RTL_DIR) {
687 env = true; //We have opened a new environment
691 if (f.family() != INHERIT_FAMILY) {
693 << LaTeXFamilyNames[f.family()]
695 count += LaTeXFamilyNames[f.family()].length() + 2;
696 env = true; //We have opened a new environment
698 if (f.series() != INHERIT_SERIES) {
700 << LaTeXSeriesNames[f.series()]
702 count += LaTeXSeriesNames[f.series()].length() + 2;
703 env = true; //We have opened a new environment
705 if (f.shape() != INHERIT_SHAPE) {
707 << LaTeXShapeNames[f.shape()]
709 count += LaTeXShapeNames[f.shape()].length() + 2;
710 env = true; //We have opened a new environment
712 if (f.color() != LColor::inherit) {
714 << lcolor.getLaTeXName(f.color())
716 count += lcolor.getLaTeXName(f.color()).length() + 13;
717 env = true; //We have opened a new environment
719 if (f.emph() == ON) {
722 env = true; //We have opened a new environment
724 if (f.underbar() == ON) {
727 env = true; //We have opened a new environment
729 // \noun{} is a LyX special macro
730 if (f.noun() == ON) {
733 env = true; //We have opened a new environment
735 if (f.size() != INHERIT_SIZE) {
736 // If we didn't open an environment above, we open one here
742 << LaTeXSizeNames[f.size()]
744 count += LaTeXSizeNames[f.size()].length() + 2;
750 /// Writes ending block of LaTeX needed to close use of this font
751 // Returns number of chars written
752 // This one corresponds to latexWriteStartChanges(). (Asger)
753 int LyXFont::latexWriteEndChanges(ostream & os, LyXFont const & base,
754 LyXFont const & next) const
756 LyXFont f = *this; // why do you need this?
757 f.reduce(base); // why isn't this just "reduce(base);" (Lgb)
758 // Because this function is const. Everything breaks if this
759 // method changes the font it represents. There is no speed penalty
760 // by using the temporary. (Asger)
762 if (f.bits == inherit)
768 FONT_DIRECTION direction = f.direction();
769 if ( direction != next.direction()
770 && (direction == RTL_DIR || direction == LTR_DIR) ) {
773 env = true; // Size change need not bother about closing env.
776 if (f.family() != INHERIT_FAMILY) {
779 env = true; // Size change need not bother about closing env.
781 if (f.series() != INHERIT_SERIES) {
784 env = true; // Size change need not bother about closing env.
786 if (f.shape() != INHERIT_SHAPE) {
789 env = true; // Size change need not bother about closing env.
791 if (f.color() != LColor::inherit) {
794 env = true; // Size change need not bother about closing env.
796 if (f.emph() == ON) {
799 env = true; // Size change need not bother about closing env.
801 if (f.underbar() == ON) {
804 env = true; // Size change need not bother about closing env.
806 if (f.noun() == ON) {
809 env = true; // Size change need not bother about closing env.
811 if (f.size() != INHERIT_SIZE) {
812 // We only have to close if only size changed
822 LColor::color LyXFont::realColor() const
825 return LColor::latex;
826 if (color() == LColor::none)
827 return LColor::foreground;
832 // Convert logical attributes to concrete shape attribute
833 LyXFont::FONT_SHAPE LyXFont::realShape() const
835 register FONT_SHAPE s = shape();
849 XFontStruct * LyXFont::getXFontstruct() const
851 return fontloader.load(family(), series(), realShape(), size());
855 int LyXFont::maxAscent() const
857 return getXFontstruct()->ascent;
861 int LyXFont::maxDescent() const
863 return getXFontstruct()->descent;
867 int LyXFont::ascent(char c) const
869 XFontStruct * finfo = getXFontstruct();
870 unsigned int uc = static_cast<unsigned char>(c);
872 && uc >= finfo->min_char_or_byte2
873 && uc <= finfo->max_char_or_byte2)
874 return finfo->per_char[uc - finfo->min_char_or_byte2].ascent;
876 return finfo->ascent;
880 int LyXFont::descent(char c) const
882 XFontStruct * finfo = getXFontstruct();
883 unsigned int uc = static_cast<unsigned char>(c);
885 && uc >= finfo->min_char_or_byte2
886 && uc <= finfo->max_char_or_byte2)
887 return finfo->per_char[uc - finfo->min_char_or_byte2].descent;
889 return finfo->descent;
893 // Specialized after profiling. (Asger)
894 int LyXFont::width(char c) const
896 if (realShape() != LyXFont::SMALLCAPS_SHAPE){
897 return XTextWidth(getXFontstruct(), &c, 1);
899 return textWidth(&c, 1);
904 int LyXFont::lbearing(char c) const
906 XFontStruct * finfo = getXFontstruct();
907 unsigned int uc = static_cast<unsigned char>(c);
909 && uc >= finfo->min_char_or_byte2
910 && uc <= finfo->max_char_or_byte2)
911 return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing;
917 int LyXFont::rbearing(char c) const
919 XFontStruct * finfo = getXFontstruct();
920 unsigned int uc = static_cast<unsigned char>(c);
922 && uc >= finfo->min_char_or_byte2
923 && uc <= finfo->max_char_or_byte2)
924 return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing;
930 int LyXFont::textWidth(char const * s, int n) const
932 if (realShape() != LyXFont::SMALLCAPS_SHAPE){
933 return XTextWidth(getXFontstruct(), s, n);
935 // emulate smallcaps since X doesn't support this
936 unsigned int result = 0;
938 LyXFont smallfont = *this;
941 smallfont.setShape(LyXFont::UP_SHAPE);
942 for (int i = 0; i < n; ++i) {
944 // when islower is a macro, the cast is needed (JMarc)
945 if (islower(static_cast<unsigned char>(c))){
947 result += XTextWidth(smallfont.getXFontstruct(), &c, 1);
949 result += XTextWidth(getXFontstruct(), &c, 1);
957 int LyXFont::stringWidth(string const & s) const
959 if (s.empty()) return 0;
960 return textWidth(s.c_str(), s.length());
964 int LyXFont::signedStringWidth(string const & s) const
966 if (s.empty()) return 0;
967 if (s.c_str()[0] == '-')
968 return -textWidth(s.c_str()+1, s.length()-1);
970 return textWidth(s.c_str(), s.length());
974 int LyXFont::drawText(char const * s, int n, Pixmap,
977 if (realShape() != LyXFont::SMALLCAPS_SHAPE) {
978 /* XDrawString(fl_display,
983 XFlush(fl_display); */
984 return XTextWidth(getXFontstruct(), s, n);
987 // emulate smallcaps since X doesn't support this
990 LyXFont smallfont = *this;
993 smallfont.setShape(LyXFont::UP_SHAPE);
994 for (int i = 0; i < n; ++i) {
996 if (islower(static_cast<unsigned char>(c))){
998 /* XDrawString(fl_display,
1003 x += XTextWidth(smallfont.getXFontstruct(),
1005 //XFlush(fl_display);
1007 /* XDrawString(fl_display,
1012 x += XTextWidth(getXFontstruct(), &c, 1);
1013 //XFlush(fl_display);
1021 int LyXFont::drawString(string const & s, Pixmap pm, int baseline, int x) const
1023 return drawText(s.c_str(), s.length(), pm, baseline, x);
1027 bool LyXFont::equalExceptLatex(LyXFont const & f) const
1030 f1.setLatex(f.latex());
1035 LyXDirection LyXFont::getFontDirection() const
1037 if (lyxrc.rtl_support
1038 && direction() == LyXFont::RTL_DIR
1039 && latex() != LyXFont::ON)
1040 return LYX_DIR_RIGHT_TO_LEFT;
1042 return LYX_DIR_LEFT_TO_RIGHT;
1046 ostream & operator<<(ostream & o, LyXFont::FONT_MISC_STATE fms)
1048 return o << int(fms);