From 354fb450c2c0e63dc96c1764bbbc5233ecae21d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Matox?= Date: Sat, 21 Oct 2006 19:40:29 +0000 Subject: [PATCH] More unicode fixes for docbook. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15459 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LaTeXFeatures.C | 14 +++++++------- src/LaTeXFeatures.h | 9 +++++---- src/buffer.C | 4 ++-- src/insets/insetgraphics.C | 24 +++++++++++------------- src/insets/insetgraphics.h | 6 +++--- src/insets/insetinclude.C | 8 ++++---- src/insets/insetinclude.h | 2 +- src/lyxlength.C | 9 +++++++++ src/lyxlength.h | 3 +++ src/mathed/MathMLStream.C | 6 ++++++ src/mathed/MathMLStream.h | 2 ++ src/paragraph.C | 1 - src/sgml.C | 4 ++-- src/sgml.h | 2 +- 14 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index 0ce379ef58..1ad591446f 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -28,8 +28,8 @@ #include "lyx_sty.h" #include "lyxrc.h" +#include "support/docstream.h" #include "support/filetools.h" - #include @@ -191,7 +191,7 @@ void LaTeXFeatures::useLanguage(Language const * lang) } -void LaTeXFeatures::includeFile(string const & key, string const & name) +void LaTeXFeatures::includeFile(docstring const & key, string const & name) { IncludedFiles_[key] = name; } @@ -498,10 +498,10 @@ string const LaTeXFeatures::getTClassPreamble() const } -string const LaTeXFeatures::getLyXSGMLEntities() const +docstring const LaTeXFeatures::getLyXSGMLEntities() const { // Definition of entities used in the document that are LyX related. - ostringstream entities; + odocstringstream entities; if (isRequired("lyxarrow")) { entities << "" << '\n'; @@ -511,9 +511,9 @@ string const LaTeXFeatures::getLyXSGMLEntities() const } -string const LaTeXFeatures::getIncludedFiles(string const & fname) const +docstring const LaTeXFeatures::getIncludedFiles(string const & fname) const { - ostringstream sgmlpreamble; + odocstringstream sgmlpreamble; string const basename = onlyPath(fname); FileMap::const_iterator end = IncludedFiles_.end(); @@ -521,7 +521,7 @@ string const LaTeXFeatures::getIncludedFiles(string const & fname) const fi != end; ++fi) sgmlpreamble << "\nfirst << (isSGMLFilename(fi->second) ? " SYSTEM \"" : " \"") - << makeRelPath(fi->second, basename) << "\">"; + << from_ascii(makeRelPath(fi->second, basename)) << "\">"; return sgmlpreamble.str(); } diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 39cba36f55..84e43dbbe2 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -15,6 +15,7 @@ #include "outputparams.h" +#include "support/docstring.h" #include #include @@ -55,11 +56,11 @@ public: /// The definitions needed by the document's textclass std::string const getTClassPreamble() const; /// The sgml definitions needed by the document (docbook) - std::string const getLyXSGMLEntities() const; + docstring const getLyXSGMLEntities() const; /// The SGML Required to include the files added with includeFile(); - std::string const getIncludedFiles(std::string const & fname) const; + docstring const getIncludedFiles(std::string const & fname) const; /// Include a file for use with the SGML entities - void includeFile(std::string const & key, std::string const & name); + void includeFile(docstring const & key, std::string const & name); /// The float definitions. void getFloatDefinitions(std::ostream & os) const; /// Print requirements to lyxerr @@ -119,7 +120,7 @@ private: /// UsedFloats usedFloats_; /// - typedef std::map FileMap; + typedef std::map FileMap; /// FileMap IncludedFiles_; /** Buffer of the file being processed. diff --git a/src/buffer.C b/src/buffer.C index e500fab155..2206d32966 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1026,7 +1026,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname, else os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\""; - string preamble = params().preamble; + docstring preamble = from_utf8(params().preamble); if (runparams.flavor != OutputParams::XML ) { preamble += "\n"; preamble += "\n"; @@ -1040,7 +1040,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname, preamble += features.getLyXSGMLEntities(); if (!preamble.empty()) { - os << "\n [ " << from_ascii(preamble) << " ]"; + os << "\n [ " << preamble << " ]"; } os << ">\n\n"; } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index b147d429c5..82c0876aa1 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -349,9 +349,9 @@ string const InsetGraphics::createLatexOptions() const } -string const InsetGraphics::toDocbookLength(LyXLength const & len) const +docstring const InsetGraphics::toDocbookLength(LyXLength const & len) const { - ostringstream result; + odocstringstream result; switch (len.unit()) { case LyXLength::SP: // Scaled point (65536sp = 1pt) TeX's smallest unit. result << len.value() * 65536.0 * 72 / 72.27 << "pt"; @@ -400,13 +400,13 @@ string const InsetGraphics::toDocbookLength(LyXLength const & len) const result << len.value() << "%"; break; default: - result << len.asString(); + result << len.asDocstring(); break; } return result.str(); } -string const InsetGraphics::createDocBookAttributes() const +docstring const InsetGraphics::createDocBookAttributes() const { // Calculate the options part of the command, we must do it to a string // stream since we copied the code from createLatexParams() ;-) @@ -414,7 +414,7 @@ string const InsetGraphics::createDocBookAttributes() const // FIXME: av: need to translate spec -> Docbook XSL spec (http://www.sagehill.net/docbookxsl/ImageSizing.html) // Right now it only works with my version of db2latex :-) - ostringstream options; + odocstringstream options; double const scl = convert(params().scale); if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) { if (!float_equal(scl, 100.0, 0.05)) @@ -436,11 +436,10 @@ string const InsetGraphics::createDocBookAttributes() const if (!params().special.empty()) - options << params().special << " "; + options << from_ascii(params().special) << " "; - string opts = options.str(); // trailing blanks are ok ... - return opts; + return options.str(); } @@ -824,7 +823,7 @@ int InsetGraphics::plaintext(Buffer const &, odocstream & os, namespace { int writeImageObject(char * format, odocstream & os, OutputParams const & runparams, - string const graphic_label, string const attributes) + docstring const graphic_label, docstring const attributes) { if (runparams.flavor != OutputParams::XML) { os << "" ; } @@ -874,7 +872,7 @@ int InsetGraphics::docbook(Buffer const &, odocstream & os, os << ""; int r = 0; - string attributes = createDocBookAttributes(); + docstring attributes = createDocBookAttributes(); r += writeImageObject("png", os, runparams, graphic_label, attributes); r += writeImageObject("pdf", os, runparams, graphic_label, attributes); r += writeImageObject("eps", os, runparams, graphic_label, attributes); diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 71930d1363..0d52776d8d 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -96,9 +96,9 @@ private: /// Create the options for the latex command. std::string const createLatexOptions() const; /// Create length values for docbook export. - std::string const toDocbookLength(LyXLength const & len) const; + docstring const toDocbookLength(LyXLength const & len) const; /// Create the atributes for docbook export. - std::string const createDocBookAttributes() const; + docstring const createDocBookAttributes() const; /// Convert the file if needed, and return the location of the file. std::string const prepareFile(Buffer const & buf, OutputParams const &) const; @@ -106,7 +106,7 @@ private: InsetGraphicsParams params_; /// holds the entity name that defines the graphics location (SGML). - std::string const graphic_label; + docstring const graphic_label; /// The thing that actually draws the image on LyX's screen. boost::scoped_ptr const graphic_; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 468f56f676..89247ce0a5 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -88,10 +88,10 @@ namespace fs = boost::filesystem; namespace { -string const uniqueID() +docstring const uniqueID() { static unsigned int seed = 1000; - return "file" + convert(++seed); + return "file" + convert(++seed); } } // namespace anon @@ -528,10 +528,10 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os, // FIXME UNICODE if (isVerbatim(params_)) { os << ""; } else - os << '&' << from_ascii(include_label) << ';'; + os << '&' << include_label << ';'; return 0; } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 23f6f17d47..cad0d6e1a1 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -119,7 +119,7 @@ private: /// the parameters InsetCommandParams params_; /// holds the entity name that defines the file location (SGML) - std::string const include_label; + docstring const include_label; /// The pointer never changes although *preview_'s contents may. boost::scoped_ptr const preview_; diff --git a/src/lyxlength.C b/src/lyxlength.C index 3b893bbb59..fded92c19b 100644 --- a/src/lyxlength.C +++ b/src/lyxlength.C @@ -19,6 +19,7 @@ #include "lengthcommon.h" #include "lyxrc.h" +#include "support/docstream.h" #include #include @@ -61,6 +62,14 @@ string const LyXLength::asString() const } +docstring const LyXLength::asDocstring() const +{ + odocstringstream os; + os << val_ << unit_name[unit_]; // setw? + return os.str(); +} + + string const LyXLength::asLatexString() const { ostringstream os; diff --git a/src/lyxlength.h b/src/lyxlength.h index e45d0f4a11..453cca1249 100644 --- a/src/lyxlength.h +++ b/src/lyxlength.h @@ -15,6 +15,7 @@ #ifndef LYX_LENGTH_H #define LYX_LENGTH_H +#include "support/docstring.h" #include @@ -81,6 +82,8 @@ public: bool empty() const; /// return string representation std::string const asString() const; + /// return string representation + docstring const asDocstring() const; /// return string representation for LaTeX std::string const asLatexString() const; /// return the on-screen size of this length diff --git a/src/mathed/MathMLStream.C b/src/mathed/MathMLStream.C index 958a815458..4958ad37b5 100644 --- a/src/mathed/MathMLStream.C +++ b/src/mathed/MathMLStream.C @@ -140,6 +140,12 @@ MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar) } +MathMLStream & operator<<(MathMLStream & ms, docstring const & s) +{ + ms.os() << s; + return ms; +} + MathMLStream & operator<<(MathMLStream & ms, char const * s) { ms.os() << s; diff --git a/src/mathed/MathMLStream.h b/src/mathed/MathMLStream.h index 36950cec89..555ff7dbef 100644 --- a/src/mathed/MathMLStream.h +++ b/src/mathed/MathMLStream.h @@ -121,6 +121,8 @@ public: int & tab() { return tab_; } /// friend MathMLStream & operator<<(MathMLStream &, char const *); + /// + friend MathMLStream & operator<<(MathMLStream &, docstring const &); private: /// odocstream & os_; diff --git a/src/paragraph.C b/src/paragraph.C index 235963b5a4..1bd903930a 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -46,7 +46,6 @@ #include "support/convert.h" #include "support/unicode.h" -#include #include #include diff --git a/src/sgml.C b/src/sgml.C index ee8fe4e150..526b51e64b 100644 --- a/src/sgml.C +++ b/src/sgml.C @@ -105,10 +105,10 @@ docstring sgml::escapeString(docstring const & raw) } -string const sgml::uniqueID(string const label) +docstring const sgml::uniqueID(string const label) { static unsigned int seed = 1000; - return label + convert(++seed); + return from_ascii(label + convert(++seed)); } diff --git a/src/sgml.h b/src/sgml.h index b4c02f5cc8..055f8638d5 100644 --- a/src/sgml.h +++ b/src/sgml.h @@ -43,7 +43,7 @@ std::string cleanID(Buffer const & buf, OutputParams const & runparams, std::string const & orig); /// returns a unique numeric id -std::string const uniqueID(std::string const label); +docstring const uniqueID(std::string const label); /// Opens tag void openTag(odocstream & os, std::string const & name, -- 2.39.5