From 99ffb47cc3dbbaf2fabbf7f4c97424eb2ab0fec7 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 9 Dec 2012 13:04:29 +0100 Subject: [PATCH] Replace some hard coded numbers with names And prevent a crash if LaTeX is accidentally output for a math font. --- src/Font.cpp | 24 +++++++++++++----------- src/FontEnums.h | 12 +++++++++--- src/FontInfo.cpp | 6 +++--- src/frontends/qt4/GuiFontLoader.cpp | 20 ++++++++++---------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/Font.cpp b/src/Font.cpp index 6e7ab34733..75952656d0 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -44,9 +44,9 @@ namespace lyx { // // These are defined in FontInfo.cpp extern char const * LyXFamilyNames[NUM_FAMILIES + 2]; -extern char const * LyXSeriesNames[4]; -extern char const * LyXShapeNames[6]; -extern char const * LyXSizeNames[14]; +extern char const * LyXSeriesNames[NUM_SERIES + 2]; +extern char const * LyXShapeNames[NUM_SHAPE + 2]; +extern char const * LyXSizeNames[NUM_SIZE + 4]; extern char const * LyXMiscNames[5]; // @@ -60,14 +60,14 @@ char const * GUIFamilyNames[NUM_FAMILIES + 2 /* default & error */] = "cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "rsfs", "wasy", "esint", N_("Inherit"), N_("Ignore") }; -char const * GUISeriesNames[4] = +char const * GUISeriesNames[NUM_SERIES + 2 /* default & error */] = { N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") }; -char const * GUIShapeNames[6] = +char const * GUIShapeNames[NUM_SHAPE + 2 /* default & error */] = { N_("Upright"), N_("Italic"), N_("Slanted"), N_("Smallcaps"), N_("Inherit"), N_("Ignore") }; -char const * GUISizeNames[14] = +char const * GUISizeNames[NUM_SIZE + 4 /* increase, decrease, default & error */] = { N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"), N_("Larger"), N_("Largest"), N_("Huge"), N_("Huger"), N_("Increase"), N_("Decrease"), N_("Inherit"), N_("Ignore") }; @@ -78,16 +78,18 @@ char const * GUIMiscNames[5] = // // Strings used to write LaTeX files // -char const * LaTeXFamilyNames[6] = -{ "textrm", "textsf", "texttt", "error1", "error2", "error3" }; +char const * LaTeXFamilyNames[NUM_FAMILIES + 2] = +{ "textrm", "textsf", "texttt", "error1", "error2", "error3", "error4", + "error5", "error6", "error7", "error8", "error9", "error10", "error11", + "error12", "error13" }; -char const * LaTeXSeriesNames[4] = +char const * LaTeXSeriesNames[NUM_SERIES + 2] = { "textmd", "textbf", "error4", "error5" }; -char const * LaTeXShapeNames[6] = +char const * LaTeXShapeNames[NUM_SHAPE + 2] = { "textup", "textit", "textsl", "textsc", "error6", "error7" }; -char const * LaTeXSizeNames[14] = +char const * LaTeXSizeNames[NUM_SIZE + 4] = { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large", "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" }; diff --git a/src/FontEnums.h b/src/FontEnums.h index 5b98604c9d..d06c5d6fa9 100644 --- a/src/FontEnums.h +++ b/src/FontEnums.h @@ -69,7 +69,9 @@ enum FontSeries { /// INHERIT_SERIES, /// - IGNORE_SERIES + IGNORE_SERIES, + /// + NUM_SERIES = INHERIT_SERIES }; /// @@ -85,7 +87,9 @@ enum FontShape { /// INHERIT_SHAPE, /// - IGNORE_SHAPE + IGNORE_SHAPE, + /// + NUM_SHAPE = INHERIT_SHAPE }; /// @@ -117,7 +121,9 @@ enum FontSize { /// FONT_SIZE_INHERIT, /// - FONT_SIZE_IGNORE + FONT_SIZE_IGNORE, + /// + NUM_SIZE = FONT_SIZE_INCREASE }; /// Used for emph, underbar, noun and latex toggles diff --git a/src/FontInfo.cpp b/src/FontInfo.cpp index d7494707d2..15054eea82 100644 --- a/src/FontInfo.cpp +++ b/src/FontInfo.cpp @@ -35,13 +35,13 @@ char const * LyXFamilyNames[NUM_FAMILIES + 2 /* default & error */] = "cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "rsfs", "wasy", "esint", "default", "error" }; -char const * LyXSeriesNames[4] = +char const * LyXSeriesNames[NUM_SERIES + 2 /* default & error */] = { "medium", "bold", "default", "error" }; -char const * LyXShapeNames[6] = +char const * LyXShapeNames[NUM_SHAPE + 2 /* default & error */] = { "up", "italic", "slanted", "smallcaps", "default", "error" }; -char const * LyXSizeNames[14] = +char const * LyXSizeNames[NUM_SIZE + 4 /* increase, decrease, default & error */] = { "tiny", "scriptsize", "footnotesize", "small", "normal", "large", "larger", "largest", "huge", "giant", "increase", "decrease", "default", "error" }; diff --git a/src/frontends/qt4/GuiFontLoader.cpp b/src/frontends/qt4/GuiFontLoader.cpp index 955303bb91..695d21b623 100644 --- a/src/frontends/qt4/GuiFontLoader.cpp +++ b/src/frontends/qt4/GuiFontLoader.cpp @@ -85,7 +85,7 @@ SymbolFont symbol_fonts[] = { size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_fonts[0]); /// BUTT ugly ! -static GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10]; +static GuiFontInfo * fontinfo_[NUM_FAMILIES][NUM_SERIES][NUM_SHAPE][NUM_SIZE]; /// Get font info (font + metrics) for the given LyX font. @@ -93,9 +93,9 @@ static GuiFontInfo * fontinfo_[NUM_FAMILIES][2][4][10]; GuiFontInfo & fontinfo(FontInfo const & f) { LASSERT(f.family() < NUM_FAMILIES, /**/); - LASSERT(f.series() < 2, /**/); - LASSERT(f.realShape() < 4, /**/); - LASSERT(f.size() < 10, /**/); + LASSERT(f.series() < NUM_SERIES, /**/); + LASSERT(f.realShape() < NUM_SHAPE, /**/); + LASSERT(f.size() < NUM_SIZE, /**/); // fi is a reference to the pointer type (GuiFontInfo *) in the // fontinfo_ table. GuiFontInfo * & fi = @@ -211,9 +211,9 @@ FontLoader::FontLoader() } for (int i1 = 0; i1 < NUM_FAMILIES; ++i1) - for (int i2 = 0; i2 < 2; ++i2) - for (int i3 = 0; i3 < 4; ++i3) - for (int i4 = 0; i4 < 10; ++i4) + for (int i2 = 0; i2 < NUM_SERIES; ++i2) + for (int i3 = 0; i3 < NUM_SHAPE; ++i3) + for (int i4 = 0; i4 < NUM_SIZE; ++i4) fontinfo_[i1][i2][i3][i4] = 0; } @@ -221,9 +221,9 @@ FontLoader::FontLoader() void FontLoader::update() { for (int i1 = 0; i1 < NUM_FAMILIES; ++i1) - for (int i2 = 0; i2 < 2; ++i2) - for (int i3 = 0; i3 < 4; ++i3) - for (int i4 = 0; i4 < 10; ++i4) { + for (int i2 = 0; i2 < NUM_SERIES; ++i2) + for (int i3 = 0; i3 < NUM_SHAPE; ++i3) + for (int i4 = 0; i4 < NUM_SIZE; ++i4) { delete fontinfo_[i1][i2][i3][i4]; fontinfo_[i1][i2][i3][i4] = 0; }