From 0667412a8920b45b5cf91af1f3d880dba0de225c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Sun, 9 Dec 2007 14:14:34 +0000 Subject: [PATCH] preamble.cpp: code simplification to r21970 suggested by Angus git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22034 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/preamble.cpp | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index ea9353bd61..3ce6ec7b4f 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -200,11 +200,25 @@ void add_package(string const & name, vector & options) } +// Given is a string like "scaled=0.9", return 0.9 * 100 +string const scale_as_percentage(string const & scale) +{ + string::size_type pos = scale.find('='); + if (pos != string::npos) { + string value = scale.substr(pos + 1); + if (isStrDbl(value)) + return convert(100 * convert(value)); + } + // If the input string didn't match our expectations. + // return the default value "100" + return "100"; +} + + void handle_package(string const & name, string const & opts) { vector options = split_options(opts); add_package(name, options); - size_t pos; string scale; // roman fonts @@ -225,17 +239,7 @@ void handle_package(string const & name, string const & opts) h_font_sans = name; if (!opts.empty()) { scale = opts; - // the option is in the form "scaled=0.9" - // therefore cut of before the "=" - pos = scale.find("="); - if (pos != string::npos) { - scale.erase(0, pos + 1); - if (isStrDbl(scale)) { - // LyX needs the scale as integer, therfore multiply by 100 - scale = convert(100 * convert(scale)); - h_font_sf_scale = scale; - } - } + h_font_sf_scale = scale_as_percentage(scale); } } // typewriter fonts @@ -243,17 +247,7 @@ void handle_package(string const & name, string const & opts) h_font_typewriter = name; if (!opts.empty()) { scale = opts; - // the option is in the form "scaled=0.9" - // therefore cut of before the "=" - pos = scale.find("="); - if (pos != string::npos) { - scale.erase(0, pos + 1); - if (isStrDbl(scale)) { - // LyX needs the scale as integer, therfore multiply by 100 - scale = convert(100 * convert(scale)); - h_font_tt_scale = scale; - } - } + h_font_tt_scale = scale_as_percentage(scale); } } // font uses old-style figure -- 2.39.2