From: Lars Gullik Bjønnes Date: Wed, 15 Dec 1999 06:12:28 +0000 (+0000) Subject: fix in lyxfont.C bogus static_cast, some changes in insetlatexaccent X-Git-Tag: 1.6.10~22468 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b3bc8c1e7121e5f0926764b2df988f1239f66523;p=features.git fix in lyxfont.C bogus static_cast, some changes in insetlatexaccent git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@380 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 920291d79c..4c32cbb42d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +1999-12-15 Lars Gullik Bjønnes + + * src/insets/insetlatexaccent.C (Lbearing): new function, used to + help with placing the manually drawn accents better. + (Rbearing): ditto + (Draw): x2 and hg changed to float to minimize rounding errors and + help place the accents better. + + * src/lyxfont.C (ascent): fixed faulty static_cast, casting from + unsigned short to char is just wrong...cast the char to unsigned + char instead so that the two values can compare sanely. This + should also make the display of insetlatexaccents better and + perhaps also some other insets. + (descent): ditto + (lbearing): new function + (rbearing): ditto + 1999-12-15 Allan Rae * src/stl_string_fwd.h, src/Makefile.am (lyx_SOURCES): added new diff --git a/acconfig.h b/acconfig.h index f78514cf08..e39c682e62 100644 --- a/acconfig.h +++ b/acconfig.h @@ -55,10 +55,10 @@ /* Define as 1 if you have the stpcopy function */ #undef HAVE_STPCPY -/* +#if 0 /* Define if the bool type is known to your compiler */ #undef HAVE_bool -*/ +#endif /* Define to the name of the distribution. */ #undef PACKAGE diff --git a/po/ca.po b/po/ca.po index 01622a6324..400608e1fd 100644 --- a/po/ca.po +++ b/po/ca.po @@ -4931,9 +4931,3 @@ msgstr "No es pot tallar la taula." #: src/text.C:3927 msgid "Float would include float!" msgstr "Un flotant inclouria un flotant!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Error! Impossible tancar el fitxer correctament: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Error! Impossible tancar el fitxer correctament: " diff --git a/po/cs.po b/po/cs.po index 839f6f4312..eed1088a00 100644 --- a/po/cs.po +++ b/po/cs.po @@ -4924,9 +4924,3 @@ msgstr "Nelze rozd #: src/text.C:3927 msgid "Float would include float!" msgstr "Objekt by obsahoval objekt!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Chyba! Nemohu správnì uzavøít soubor: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Chyba! Nemonu strávnì uzavøít soubor:" diff --git a/po/da.po b/po/da.po index be0b8e8314..86ee2304d3 100644 --- a/po/da.po +++ b/po/da.po @@ -4970,9 +4970,3 @@ msgstr "Kan ikke klippe tabel." #: src/text.C:3927 msgid "Float would include float!" msgstr "Flyder ville inkludere flyder!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Fejl! Filen blev ikke lukket korrekt: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Fejl: Filen blev ikke lukket korrekt:" diff --git a/po/de.po b/po/de.po index b3738c0dfb..98586e7a6e 100644 --- a/po/de.po +++ b/po/de.po @@ -4952,9 +4952,3 @@ msgstr "Die Tabelle kann nicht ausgeschnitten werden." #: src/text.C:3927 msgid "Float would include float!" msgstr "Float Objekt würde ein weiteres enthalten!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Fehler! Die Datei konnte nicht ordnungsgemäß geschlossen werden: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Fehler! Die Datei konnte nicht ordnungsgemäß geschlossen werden: " diff --git a/po/es.po b/po/es.po index fd9a7b86a5..f73e4fe858 100644 --- a/po/es.po +++ b/po/es.po @@ -4963,9 +4963,3 @@ msgstr "No se puede cortar tabla." #: src/text.C:3927 msgid "Float would include float!" msgstr "¡Flotante incluiría un flotante!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "¡Error! No se pudo cerrar el archivo correctamente: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "¡Error! No se puede cerrar el archivo correctamente:" diff --git a/po/fi.po b/po/fi.po index f0d96e153e..58b0f40467 100644 --- a/po/fi.po +++ b/po/fi.po @@ -4947,9 +4947,3 @@ msgstr "Ei voi jakaa taulukkoa." #: src/text.C:3927 msgid "Float would include float!" msgstr "Kelluva sisältäisi kelluvan!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Virhe! En saanut tiedosto kunnolla suljetuksi: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Virhe! En saanut tiedosto kunnolla suljetuksi:" diff --git a/po/fr.po b/po/fr.po index a6c5c1a51e..fda4ffa245 100644 --- a/po/fr.po +++ b/po/fr.po @@ -4978,9 +4978,3 @@ msgstr "Impossible de couper le tableau." #: src/text.C:3927 msgid "Float would include float!" msgstr "Un flottant inclurait un flottant !" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Erreur ! Impossible de fermer le fichier correctement : " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Erreur ! Impossible de fermer le fichier correctement : " diff --git a/po/hu.po b/po/hu.po index 402fd7362c..2bd5627ba1 100644 --- a/po/hu.po +++ b/po/hu.po @@ -4940,9 +4940,3 @@ msgstr "" #: src/text.C:3927 msgid "Float would include float!" msgstr "" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Hiba! Nem sikerült a fájlt rendesen bezárni: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Hiba! Nem sikerült a fájlt rendesen bezárni:" diff --git a/po/it.po b/po/it.po index 278630794c..9a4b21d8ff 100644 --- a/po/it.po +++ b/po/it.po @@ -4958,9 +4958,3 @@ msgstr "Non puoi tagliare una tabella." #: src/text.C:3927 msgid "Float would include float!" msgstr "L'oggetto flottante ne includerebbe un altro!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Errore! Non riesco a chiudere correttamente il file: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Errore! Non riesco a chiudere correttamente il file:" diff --git a/po/nl.po b/po/nl.po index 38a4aedd9f..0d9ae74ffd 100644 --- a/po/nl.po +++ b/po/nl.po @@ -4977,9 +4977,3 @@ msgstr "Kan tabel niet splitsen." #: src/text.C:3927 msgid "Float would include float!" msgstr "Hier zou een zwever een andere zwever bevatten!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Fout! Kon bestand niet op juiste wijze sluiten: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Fout! Kon bestand niet op juiste wijze sluiten:" diff --git a/po/pl.po b/po/pl.po index 010174e55d..46a969290e 100644 --- a/po/pl.po +++ b/po/pl.po @@ -4924,9 +4924,3 @@ msgstr "Nie mo #: src/text.C:3927 msgid "Float would include float!" msgstr "Wstawka móg³aby zawieraæ inn± wstawkê!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "B³±d! Nie mo¿na poprawnie zamkn±æ pliku: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "B³±d! Nie mo¿na poprawnie zamkn±æ pliku:" diff --git a/po/pt.po b/po/pt.po index 10458f55f1..1be140bcc1 100644 --- a/po/pt.po +++ b/po/pt.po @@ -4975,9 +4975,3 @@ msgstr "N #: src/text.C:3927 msgid "Float would include float!" msgstr "Flutuante incluiria flutuante!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Erro! Não posso fechar corretamente o arquivo" - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Erro! Não posso fechar corretamente o arquivo" diff --git a/po/ru.po b/po/ru.po index 21d7b3ff8f..adf9f18e1a 100644 --- a/po/ru.po +++ b/po/ru.po @@ -4998,9 +4998,3 @@ msgstr " #: src/text.C:3927 msgid "Float would include float!" msgstr "ëÁÄÒ ÄÏÌÖÅÎ ×ËÌÀÞÁÔØ ËÁÄÒ!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "ïÛÉÂËÁ ÚÁËÒÙÔÉÑ ÆÁÊÌÁ " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "ïÛÉÂËÁ ÚÁËÒÙÔÉÑ ÆÁÊÌÁ " diff --git a/po/sl.po b/po/sl.po index 3ce8e241ee..292c39fd98 100644 --- a/po/sl.po +++ b/po/sl.po @@ -4937,9 +4937,3 @@ msgstr "Ne morem razkosati tabele." #: src/text.C:3927 msgid "Float would include float!" msgstr "Plovka bi vkljuèevala plovko!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Napaka! Ne morem pravilno zapreti datoteke: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Napaka! Ne morem pravilno zapreti datoteke:" diff --git a/po/sv.po b/po/sv.po index 84c33aa01c..fd917c5c83 100644 --- a/po/sv.po +++ b/po/sv.po @@ -5062,9 +5062,3 @@ msgstr "Kan inte klippa tabell." #: src/text.C:3927 msgid "Float would include float!" msgstr "Flytande objekt skulle då innefatta ett annat!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Fel! Kunde inte stänga filen ordentligt: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Fel: Kunde inte stänga filen ordentligt:" diff --git a/po/tr.po b/po/tr.po index ae40f73822..1ccd59009d 100644 --- a/po/tr.po +++ b/po/tr.po @@ -4996,9 +4996,3 @@ msgstr "Tabloyu kesemem." #: src/text.C:3927 msgid "Float would include float!" msgstr "Tek-parça, tek-parça içermeli!" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Hata! Dosya düzgün olarak kapatýlamadý: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Hata! Dosya düzgün kapatýlamadý:" diff --git a/po/wa.po b/po/wa.po index ab29fe825c..947df797e8 100644 --- a/po/wa.po +++ b/po/wa.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: LyX 1.0.0\n" "POT-Creation-Date: 1999-12-13 23:06+0100\n" -"PO-Revision-Date: 1999-12-01 00:26+01:00\n" +"PO-Revision-Date: 1999-12-13 23:40+01:00\n" "Last-Translator: Lorint Hendschel \n" "Language-Team: walon \n" "MIME-Version: 1.0\n" @@ -4982,9 +4982,3 @@ msgstr "Dji n' sai c #: src/text.C:3927 msgid "Float would include float!" msgstr "I gn åreut on flotant di stitchî dins èn ôte flotant !" - -#~ msgid "Error! Could not close file properly: " -#~ msgstr "Aroke! Dji n' sai cloyu ci fitchî la comufåt: " - -#~ msgid "Error! Could not close file properly:" -#~ msgstr "Aroke! Dji n' sai cloyu ci fitchî ci comufåt: " diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index f26d3d8a8b..8b018478a1 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -264,6 +264,10 @@ void InsetLatexAccent::checkContents() int InsetLatexAccent::Ascent(LyXFont const & font) const { + // This function is a bit too simplistix and is just a + // "try to make a fit for all accents" approach, to + // make it better we need to know what kind of accent is + // used and add to max based on that. int max; if (candisp) { if (ic == ' ') @@ -303,6 +307,18 @@ int InsetLatexAccent::Width(LyXFont const & font) const } +int InsetLatexAccent::Lbearing(LyXFont const & font) const +{ + return font.lbearing(ic); +} + + +int InsetLatexAccent::Rbearing(LyXFont const & font) const +{ + return font.rbearing(ic); +} + + bool InsetLatexAccent::DisplayISO8859_9(LyXFont font, LyXScreen & scr, int baseline, @@ -357,73 +373,80 @@ void InsetLatexAccent::Draw(LyXFont font, return; /* draw it! */ - + // All the manually drawn accents in this function could use an + // overhaul. Different ways of drawing (what metrics to use) + // should also be considered. + if (candisp) { int asc = Ascent(font); int desc = Descent(font); int wid = Width(font); - float x2 = x + float(wid/2); + float x2 = x + (Rbearing(font) - Lbearing(font)) / 2.0; float hg35; - int hg, y; + float hg; + int y; if (plusasc) { // mark at the top hg = font.maxDescent(); y = baseline - asc; - if (font.shape() == LyXFont::ITALIC_SHAPE) x2 += (4*hg)/5; // italic + if (font.shape() == LyXFont::ITALIC_SHAPE) + x2 += (4.0 * hg) / 5.0; // italic } else { // at the bottom hg = desc; y = baseline; } - hg35 = float(hg*3)/5; + hg35 = float(hg * 3.0) / 5.0; // display with proper accent mark // first the letter scr.drawText(font, &ic, 1, baseline, int(x)); - GC pgc = GetAccentGC(font, (hg+3)/5); + GC pgc = GetAccentGC(font, int((hg + 3.0) / 5.0)); if (remdot) { int tmpvar = baseline - font.ascent('i'); float tmpx = 0; - if (font.shape() == LyXFont::ITALIC_SHAPE) tmpx += (8*hg)/10; // italic + if (font.shape() == LyXFont::ITALIC_SHAPE) + tmpx += (8.0 * hg) / 10.0; // italic lyxerr.debug() << "Removing dot." << endl; // remove the dot first scr.fillRectangle(gc_clear, int(x + tmpx), tmpvar, wid, font.ascent('i') - - font.ascent('x')-1); - + font.ascent('x') - 1); } // now the rest - draw within (x, y, x+wid, y+hg) switch (modtype) { case ACUTE: // acute { - scr.drawLine(pgc, int(x2), int(y+hg35), - int(x2+hg35), y); + scr.drawLine(pgc, int(x2), int(y + hg35), + int(x2 + hg35), y); break; } case GRAVE: // grave { - scr.drawLine(pgc, int(x2), int(y+hg35), - int(x2-hg35), y); + scr.drawLine(pgc, int(x2), int(y + hg35), + int(x2 - hg35), y); break; } case MACRON: // macron { scr.drawLine(pgc, - int(x2-(3*wid/7)), int(y+(hg/2) + hg35), - int(x2+(3*wid/7)), int(y+(hg/2) + hg35)); + int(x2 - (3.0 * wid / 7.0)), + int(y + (hg / 2.0) + hg35), + int(x2 + (3.0 * wid / 7.0)), + int(y + (hg / 2.0) + hg35)); break; } case TILDE: // tilde { - if (hg35 > 2) --hg35; - x2 += (hg35/2); + if (hg35 > 2.0) hg35 -= 1.0; + x2 += (hg35 / 2.0); XPoint p[4]; - p[0].x = int(x2 - 2*hg35); p[0].y = int(y + hg); + p[0].x = int(x2 - 2.0 * hg35); p[0].y = int(y + hg); p[1].x = int(x2 - hg35); p[1].y = int(y + hg35); p[2].x = int(x2); p[2].y = int(y + hg); p[3].x = int(x2 + hg35); p[3].y = int(y + hg35); @@ -433,44 +456,48 @@ void InsetLatexAccent::Draw(LyXFont font, case UNDERBAR: // underbar { scr.drawLine(pgc, - int(x2-(3*wid/7)), y+(hg/2), - int(x2+(3*wid/7)), y+(hg/2)); + int(x2 - (3.0 * wid / 7.0)), + y + (hg / 2.0), + int(x2 + (3.0 * wid / 7.0)), + y + (hg / 2.0)); break; } case CEDILLA: // cedilla { XPoint p[4]; p[0].x = int(x2); p[0].y = y; - p[1].x = int(x2); p[1].y = y + (hg/3); - p[2].x = int(x2 + (hg/3)); p[2].y = y + (hg/2); - p[3].x = int(x2 - (hg/4)); p[3].y = y + hg; + p[1].x = int(x2); p[1].y = y + int(hg / 3.0); + p[2].x = int(x2 + (hg / 3.0)); + p[2].y = y + int(hg / 2.0); + p[3].x = int(x2 - (hg / 4.0)); p[3].y = y + int(hg); scr.drawLines(pgc, p, 4); break; } case UNDERDOT: // underdot case DOT: // dot { - scr.drawArc(pgc, int(x2), y+(hg/2), + scr.drawArc(pgc, int(x2), y + (hg / 2.0), 1, 1, 0, 360*64); break; } case CIRCLE: // circle { - scr.drawArc(pgc, int(x2-(hg/2)), y, hg, hg, 0, + scr.drawArc(pgc, int(x2 - (hg / 2.0)), + y + (hg / 2.0), hg, hg, 0, 360*64); break; } case TIE: // tie { scr.drawArc(pgc, - int(x2), y+(hg/4), + int(x2), y + (hg / 4.0), hg, hg, 0, 11519); break; } case BREVE: // breve { scr.drawArc(pgc, - int(x2-(hg/2)), y-(hg/4), + int(x2 - (hg / 2.0)), y - (hg / 4.0), hg, hg, 0, -11519); break; } @@ -478,7 +505,7 @@ void InsetLatexAccent::Draw(LyXFont font, { XPoint p[3]; p[0].x = int(x2 - hg35); p[0].y = y; - p[1].x = int(x2); p[1].y = int(y+hg35); + p[1].x = int(x2); p[1].y = int(y + hg35); p[2].x = int(x2 + hg35); p[2].y = y; scr.drawLines(pgc, p, 3); break; @@ -486,49 +513,60 @@ void InsetLatexAccent::Draw(LyXFont font, case SPECIAL_CARON: // special caron { switch (ic) { - case 'L': wid = 4*wid/5; break; - case 't': y -= int(hg35/2); break; + case 'L': wid = int(4.0 * wid / 5.0); break; + case 't': y -= int(hg35 / 2.0); break; } XPoint p[3]; - p[0].x = int(x+wid); p[0].y = int(y+hg35+hg); - p[1].x = int(x+wid+(hg35/2)); p[1].y = int(y+ hg+(hg35/2)); - p[2].x = int(x+wid+(hg35/2)); p[2].y = y + hg; + p[0].x = int(x + wid); p[0].y = int(y + hg35 + hg); + p[1].x = int(x + wid + (hg35 / 2.0)); + p[1].y = int(y + hg + (hg35 / 2.0)); + p[2].x = int(x + wid + (hg35 / 2.0)); + p[2].y = y + int(hg); scr.drawLines(pgc, p, 3); break; } case HUNGARIAN_UMLAUT: // hung. umlaut { XSegment s[2]; - s[0].x1= int(x2-(hg/2)); s[0].y1 = int(y + hg35); - s[0].x2= int(x2+hg35-(hg/2)); s[0].y2 = y; - s[1].x1= int(x2+(hg/2)); s[1].y1 = int(y + hg35); - s[1].x2= int(x2+hg35+(hg/2)); s[1].y2 = y; + s[0].x1= int(x2 - (hg / 2.0)); s[0].y1 = int(y + hg35); + s[0].x2= int(x2 + hg35 - (hg / 2.0)); s[0].y2 = y; + s[1].x1= int(x2 + (hg / 2.0)); + s[1].y1 = int(y + hg35); + s[1].x2= int(x2 + hg35 + (hg / 2.0)); s[1].y2 = y; scr.drawSegments(pgc, s, 2); break; } case UMLAUT: // umlaut { - int tmpadd = y; - tmpadd += (remdot) ? ((19*hg)/10) : ((20*hg)/27); // if (remdot) -> i or j - int rad = ((hg*4)/8); - if (rad <= 1) { - scr.drawPoint(pgc, int(x2-((4*hg)/7)), tmpadd); - scr.drawPoint(pgc, int(x2+((4*hg)/7)), tmpadd); + float tmpadd = y; + tmpadd += (remdot) ? + asc/3.0 : + asc/5.0; // if (remdot) -> i or j + float rad = ((hg * 4.0) / 8.0); + if (rad <= 1.0) { + scr.drawPoint(pgc, + int(x2 - ((4.0 * hg) / 7.0)), + tmpadd); + scr.drawPoint(pgc, + int(x2 + ((4.0 * hg) / 7.0)), + tmpadd); } else { - scr.drawArc(pgc, int(x2-((2*hg)/4)), tmpadd, - rad-1, rad-1, 0, 360*64); - scr.drawArc(pgc, int(x2+((2*hg)/4)), tmpadd, - rad-1, rad-1, 0, 360*64); + scr.drawArc(pgc, int(x2 - ((2.0 * hg) / 4.0)), + tmpadd, + rad - 1, rad - 1, 0, 360*64); + scr.drawArc(pgc, int(x2 + ((2.0 * hg) / 4.0)), + tmpadd, + rad - 1, rad - 1, 0, 360*64); } break; } case CIRCUMFLEX: // circumflex { XPoint p[3]; - p[0].x = int(x2 - hg35); p[0].y = y + hg; + p[0].x = int(x2 - hg35); p[0].y = y + int(hg); p[1].x = int(x2); p[1].y = int(y + hg35); - p[2].x = int(x2 + hg35); p[2].y = y + hg; + p[2].x = int(x2 + hg35); p[2].y = y + int(hg); scr.drawLines(pgc, p, 3); break; } @@ -538,9 +576,10 @@ void InsetLatexAccent::Draw(LyXFont font, // it should certainly be refined XPoint p[4]; p[0].x = int(x2); p[0].y = y; - p[1].x = int(x2); p[1].y = y + (hg/3); - p[2].x = int(x2 - (hg/3)); p[2].y = y + (hg/2); - p[3].x = int(x2 + (hg/4)); p[3].y = y + hg; + p[1].x = int(x2); p[1].y = y + int(hg / 3.0); + p[2].x = int(x2 - (hg / 3.0)); + p[2].y = y + int(hg / 2.0); + p[3].x = int(x2 + (hg / 4.0)); p[3].y = y + int(hg); scr.drawLines(pgc, p, 4); break; } @@ -548,8 +587,10 @@ void InsetLatexAccent::Draw(LyXFont font, case LSLASH: { XPoint p[2]; - p[0].x = int(x); p[0].y = y+3*hg; - p[1].x = int(x+float(wid)*.75); p[1].y = y+hg; + p[0].x = int(x); + p[0].y = y + int(3.0 * hg); + p[1].x = int(x + float(wid) * 0.75); + p[1].y = y + int(hg); scr.drawLines(pgc, p, 2); break; } @@ -562,15 +603,15 @@ void InsetLatexAccent::Draw(LyXFont font, } } else { scr.fillRectangle(gc_lighted, - int(x+1), baseline - Ascent(font)+1, - Width(font)-2, - Ascent(font)+Descent(font)-2); + int(x + 1), baseline - Ascent(font) + 1, + Width(font) - 2, + Ascent(font) + Descent(font) - 2); scr.drawRectangle(gc_lighted, int(x), baseline - Ascent(font), - Width(font)-1, - Ascent(font)+Descent(font)-1); - scr.drawString(font, contents, baseline, int(x+2)); + Width(font) - 1, + Ascent(font) + Descent(font) - 1); + scr.drawString(font, contents, baseline, int(x + 2)); } x += Width(font); } diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 424a3444f2..47aa293175 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -42,6 +42,10 @@ public: /// int Width(LyXFont const & font) const; /// + int Lbearing(LyXFont const & font) const; + /// + int Rbearing(LyXFont const & font) const; + /// bool DisplayISO8859_9(LyXFont font, LyXScreen & scr, int baseline, float & x); /// diff --git a/src/lyxdraw.C b/src/lyxdraw.C index cba27858dc..9385f7482c 100644 --- a/src/lyxdraw.C +++ b/src/lyxdraw.C @@ -432,7 +432,7 @@ GC GetColorGC(LyXFont::FONT_COLOR color) GC GetAccentGC(LyXFont const &f, int line_width) { - if (line_width>= 10) line_width = 9; + if (line_width >= 10) line_width = 9; if (accent_gc[line_width]) return accent_gc[line_width]; diff --git a/src/lyxfont.C b/src/lyxfont.C index 2e10553633..447979c540 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -376,14 +376,14 @@ LyXFont & LyXFont::setLyXFamily(string const & fam) { string s = lowercase(fam); - int i= 0; - while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") i++; + int i = 0; + while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") ++i; if (s == LyXFamilyNames[i]) { setFamily(LyXFont::FONT_FAMILY(i)); } else lyxerr << "LyXFont::setLyXFamily: Unknown family `" << s << '\'' << endl; - return (*this); + return *this; } @@ -392,14 +392,14 @@ LyXFont & LyXFont::setLyXSeries(string const & ser) { string s = lowercase(ser); - int i= 0; - while (s != LyXSeriesNames[i] && LyXSeriesNames[i] != "error") i++; + int i = 0; + while (s != LyXSeriesNames[i] && LyXSeriesNames[i] != "error") ++i; if (s == LyXSeriesNames[i]) { setSeries(LyXFont::FONT_SERIES(i)); } else lyxerr << "LyXFont::setLyXSeries: Unknown series `" << s << '\'' << endl; - return (*this); + return *this; } @@ -408,14 +408,14 @@ LyXFont & LyXFont::setLyXShape(string const & sha) { string s = lowercase(sha); - int i= 0; - while (s != LyXShapeNames[i] && LyXShapeNames[i] != "error") i++; + int i = 0; + while (s != LyXShapeNames[i] && LyXShapeNames[i] != "error") ++i; if (s == LyXShapeNames[i]) { setShape(LyXFont::FONT_SHAPE(i)); } else lyxerr << "LyXFont::setLyXShape: Unknown shape `" << s << '\'' << endl; - return (*this); + return *this; } @@ -423,14 +423,14 @@ LyXFont & LyXFont::setLyXShape(string const & sha) LyXFont & LyXFont::setLyXSize(string const & siz) { string s = lowercase(siz); - int i= 0; - while (s != LyXSizeNames[i] && LyXSizeNames[i] != "error") i++; + int i = 0; + while (s != LyXSizeNames[i] && LyXSizeNames[i] != "error") ++i; if (s == LyXSizeNames[i]) { setSize(LyXFont::FONT_SIZE(i)); } else lyxerr << "LyXFont::setLyXSize: Unknown size `" << s << '\'' << endl; - return (*this); + return *this; } // Set size according to lyx format string @@ -438,7 +438,7 @@ LyXFont::FONT_MISC_STATE LyXFont::setLyXMisc(string const & siz) { string s = lowercase(siz); int i= 0; - while (s != LyXMiscNames[i] && LyXMiscNames[i] != "error") i++; + while (s != LyXMiscNames[i] && LyXMiscNames[i] != "error") ++i; if (s == LyXMiscNames[i]) return FONT_MISC_STATE(i); lyxerr << "LyXFont::setLyXMisc: Unknown misc flag `" @@ -451,13 +451,13 @@ LyXFont & LyXFont::setLyXColor(string const & col) { string s = lowercase(col); int i= 0; - while (s != LyXColorNames[i] && LyXColorNames[i] != "error") i++; + while (s != LyXColorNames[i] && LyXColorNames[i] != "error") ++i; if (s == LyXColorNames[i]) { setColor(LyXFont::FONT_COLOR(i)); } else lyxerr << "LyXFont::setLyXColor: Unknown Color `" << s << '\'' << endl; - return (*this); + return *this; } @@ -465,16 +465,16 @@ LyXFont & LyXFont::setLyXColor(string const & col) LyXFont & LyXFont::setGUISize(string const & siz) { string s = lowercase(siz); - int i= 0; + int i = 0; while (!lGUISizeNames[i].empty() && s != _(lGUISizeNames[i].c_str())) - i++; + ++i; if (s == _(lGUISizeNames[i].c_str())) { setSize(LyXFont::FONT_SIZE(i)); } else lyxerr << "LyXFont::setGUISize: Unknown Size `" << s << '\'' << endl; - return (*this); + return *this; } @@ -813,8 +813,8 @@ int LyXFont::ascent(char c) const { XFontStruct * finfo = getXFontstruct(); if (finfo->per_char - && c >= static_cast(finfo->min_char_or_byte2) - && c <= static_cast(finfo->max_char_or_byte2)) { + && static_cast(c) >= finfo->min_char_or_byte2 + && static_cast(c) <= finfo->max_char_or_byte2) { unsigned int index = c - finfo->min_char_or_byte2; return finfo->per_char[index].ascent; } else @@ -826,8 +826,8 @@ int LyXFont::descent(char c) const { XFontStruct * finfo = getXFontstruct(); if (finfo->per_char - && c >= static_cast(finfo->min_char_or_byte2) - && c <= static_cast(finfo->max_char_or_byte2)) { + && static_cast(c) >= finfo->min_char_or_byte2 + && static_cast(c) <= finfo->max_char_or_byte2) { unsigned int index = c - finfo->min_char_or_byte2; return finfo->per_char[index].descent; } else @@ -846,6 +846,32 @@ int LyXFont::width(char c) const } +int LyXFont::lbearing(char c) const +{ + XFontStruct * finfo = getXFontstruct(); + if (finfo->per_char + && static_cast(c) >= finfo->min_char_or_byte2 + && static_cast(c) <= finfo->max_char_or_byte2) { + unsigned int index = c - finfo->min_char_or_byte2; + return finfo->per_char[index].lbearing; + } else + return 0; +} + + +int LyXFont::rbearing(char c) const +{ + XFontStruct * finfo = getXFontstruct(); + if (finfo->per_char + && static_cast(c) >= finfo->min_char_or_byte2 + && static_cast(c) <= finfo->max_char_or_byte2) { + unsigned int index = c - finfo->min_char_or_byte2; + return finfo->per_char[index].rbearing; + } else + return width(c); +} + + int LyXFont::textWidth(char const * s, int n) const { if (realShape() != LyXFont::SMALLCAPS_SHAPE){ @@ -858,7 +884,7 @@ int LyXFont::textWidth(char const * s, int n) const smallfont.decSize(); smallfont.decSize(); smallfont.setShape(LyXFont::UP_SHAPE); - for (int i= 0; i < n; i++){ + for (int i = 0; i < n; ++i) { c = s[i]; if (islower(c)){ c = toupper(c); @@ -909,7 +935,7 @@ int LyXFont::drawText(char const * s, int n, Pixmap pm, smallfont.decSize(); smallfont.decSize(); smallfont.setShape(LyXFont::UP_SHAPE); - for (int i = 0; i < n; ++i){ + for (int i = 0; i < n; ++i) { c = s[i]; if (islower(c)){ c = toupper(c); diff --git a/src/lyxfont.h b/src/lyxfont.h index f63d1f5ef8..f495367466 100644 --- a/src/lyxfont.h +++ b/src/lyxfont.h @@ -330,6 +330,12 @@ public: /// int width(char c) const; + /// + int lbearing(char c) const; + + /// + int rbearing(char c) const; + /// int textWidth(char const *s, int n) const; diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 071e0dce00..ad42eac29f 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -10,6 +10,7 @@ #include "LRegex.h" using std::count; +using std::transform; bool isStrInt(string const & str) { @@ -44,17 +45,31 @@ int strToInt(string const & str) string lowercase(string const & a) { +#if 0 string tmp; string::const_iterator cit = a.begin(); for(; cit != a.end(); ++cit) { tmp += static_cast(tolower(*cit)); } return tmp; +#endif + string tmp(a); + transform(tmp.begin(), tmp.end(), tmp.begin(), tolower); + return tmp; +} + + +string uppercase(string const & a) +{ + string tmp(a); + transform(tmp.begin(), tmp.end(), tmp.begin(), toupper); + return tmp; } string tostr(long i) { + // should use string stream char str[30]; sprintf(str, "%ld", i); return string(str); @@ -63,6 +78,7 @@ string tostr(long i) string tostr(unsigned long i) { + // should use string stream char str[30]; sprintf(str, "%lu", i); return string(str); @@ -109,6 +125,7 @@ string tostr(float f) string tostr(double d) { + // should use string stream char tmp[40]; sprintf(tmp, "%f", d); return string(tmp); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 790629d234..d29fbe8e38 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -99,6 +99,9 @@ int strToInt(string const & str); /// string lowercase(string const &); +/// +string uppercase(string const &); + /// int to string string tostr(int i); diff --git a/src/support/lyxstring.C b/src/support/lyxstring.C index fd22e800c9..c3d1af1275 100644 --- a/src/support/lyxstring.C +++ b/src/support/lyxstring.C @@ -271,7 +271,7 @@ void lyxstring::Srep::reserve(lyxstring::size_type res_arg) void lyxstring::Srep::replace(lyxstring::size_type i, lyxstring::size_type n, - value_type const * p, size_type n2) + value_type const * p, size_type n2) { // can be called with p= 0 and n2= 0 n = min(sz - i, n);