X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffont.C;h=5a6f4fa74727db4355a430db335c316c46c65b67;hb=f448e22d483e1370bcbfbb7be8cb47ad7251ed77;hp=462241db9675eb7b1cb70853e239be2986f36f19;hpb=4b2a999762c83627476428e595d3c1e3704a3da0;p=lyx.git diff --git a/src/font.C b/src/font.C index 462241db96..5a6f4fa747 100644 --- a/src/font.C +++ b/src/font.C @@ -55,7 +55,7 @@ int lyxfont::ascent(char c, LyXFont const & f) unsigned int uc = static_cast(c); if (finfo->per_char && uc >= finfo->min_char_or_byte2 - && uc <= finfo->max_char_or_byte2) + && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1) return finfo->per_char[uc - finfo->min_char_or_byte2].ascent; else return finfo->ascent; @@ -68,7 +68,7 @@ int lyxfont::descent(char c, LyXFont const & f) unsigned int uc = static_cast(c); if (finfo->per_char && uc >= finfo->min_char_or_byte2 - && uc <= finfo->max_char_or_byte2) + && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1) return finfo->per_char[uc - finfo->min_char_or_byte2].descent; else return finfo->descent; @@ -81,7 +81,7 @@ int lyxfont::lbearing(char c, LyXFont const & f) unsigned int uc = static_cast(c); if (finfo->per_char && uc >= finfo->min_char_or_byte2 - && uc <= finfo->max_char_or_byte2) + && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1) return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing; else return 0; @@ -94,14 +94,14 @@ int lyxfont::rbearing(char c, LyXFont const & f) unsigned int uc = static_cast(c); if (finfo->per_char && uc >= finfo->min_char_or_byte2 - && uc <= finfo->max_char_or_byte2) + && uc <= finfo->max_char_or_byte2+256*finfo->max_byte1) return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing; else return width(c, f); } -int lyxfont::width(char const * s, int n, LyXFont const & f) +int lyxfont::width(char const * s, size_t n, LyXFont const & f) { if (!lyxrc.use_gui) return n; @@ -109,22 +109,23 @@ int lyxfont::width(char const * s, int n, LyXFont const & f) if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) { XChar2b * xs = new XChar2b[n]; Encoding const * encoding = f.language()->encoding(); - LyXFont const * font = &f; + //LyXFont const * font = &f; + LyXFont font(f); if (f.family() == LyXFont::SYMBOL_FAMILY) { #ifdef USE_UNICODE_FOR_SYMBOLS - LyXFont font2 = f; - font2.setFamily(LyXFont::ROMAN_FAMILY); - font2.setShape(LyXFont::UP_SHAPE); - font = &font2; + //LyXFont font2 = f; + font.setFamily(LyXFont::ROMAN_FAMILY); + font.setShape(LyXFont::UP_SHAPE); + //font = &font2; #endif - encoding = &symbol_encoding; + encoding = encodings.symbol_encoding(); } - for (int i = 0; i < n; ++i) { + for (size_t i = 0; i < n; ++i) { Uchar c = encoding->ucs(s[i]); xs[i].byte1 = c >> 8; xs[i].byte2 = c & 0xff; } - int result = width(xs, n, *font); + int result = width(xs, n, font); delete[] xs; return result; } @@ -137,7 +138,7 @@ int lyxfont::width(char const * s, int n, LyXFont const & f) char c; LyXFont smallfont(f); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); - for (int i = 0; i < n; ++i) { + for (size_t i = 0; i < n; ++i) { c = s[i]; // when islower is a macro, the cast is needed (JMarc) if (islower(static_cast(c))) { @@ -155,13 +156,14 @@ int lyxfont::width(char const * s, int n, LyXFont const & f) int lyxfont::signedWidth(string const & s, LyXFont const & f) { if (s.empty()) return 0; - if (s.c_str()[0] == '-') - return -width(s.c_str() + 1, s.length() - 1, f); + if (s[0] == '-') + return -width(s.substr(1, s.length() - 1), f); else - return width(s.c_str(), s.length(), f); + return width(s, f); } +//int lyxfont::width(wstring const & s, int n, LyXFont const & f) int lyxfont::width(XChar2b const * s, int n, LyXFont const & f) { if (!lyxrc.use_gui) @@ -187,13 +189,13 @@ int lyxfont::width(XChar2b const * s, int n, LyXFont const & f) } } -int lyxfont::XTextWidth(LyXFont const & f, char * str, int count) +int lyxfont::XTextWidth(LyXFont const & f, char const * str, int count) { return ::XTextWidth(getXFontstruct(f), str, count); } -int lyxfont::XTextWidth16(LyXFont const & f, XChar2b * str, int count) +int lyxfont::XTextWidth16(LyXFont const & f, XChar2b const * str, int count) { return ::XTextWidth16(getXFontstruct(f), str, count); }