]> git.lyx.org Git - features.git/commitdiff
Prevent access to null local_font
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 30 Sep 2023 11:01:20 +0000 (13:01 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 30 Sep 2023 11:01:20 +0000 (13:01 +0200)
12 files changed:
src/insets/Inset.cpp
src/insets/Inset.h
src/insets/InsetBox.cpp
src/insets/InsetFloatList.cpp
src/insets/InsetIndex.cpp
src/insets/InsetListings.cpp
src/insets/InsetNomencl.cpp
src/insets/InsetQuotes.cpp
src/insets/InsetRef.cpp
src/insets/InsetSpace.cpp
src/insets/InsetSpecialChar.cpp
src/insets/InsetTabular.cpp

index 6e89950f9644d8d8c562fa54883df887d3ffea7c..6e3bb67a9de1ff7d538c4f8b052c7597ffda44dd 100644 (file)
@@ -672,4 +672,12 @@ docstring Inset::completionPrefix(Cursor const &) const
        return docstring();
 }
 
+
+Language const * Inset::getLocalOrDefaultLang(const OutputParams & rp) const
+{
+       return (rp.local_font != nullptr)
+                       ? rp.local_font->language()
+                       : buffer().params().language;
+}
+
 } // namespace lyx
index 1b7adb5e8986d3fae050cbf057f9431734eaafe3..04fffe950bc2a2e6689fd73117c3663ff5d56ce8 100644 (file)
@@ -54,6 +54,7 @@ class InsetList;
 class InsetMath;
 class InsetTabular;
 class InsetText;
+class Language;
 class LaTeXFeatures;
 class Lexer;
 class MathAtom;
@@ -618,6 +619,9 @@ public:
        /// Determine the action of backspace and delete: do we select instead of
        /// deleting if not already selected?
        virtual bool confirmDeletion() const { return false; }
+       /// Return the local_font's language or the buffer's default language
+       /// if local_font is null
+       Language const * getLocalOrDefaultLang(const OutputParams &) const;
 
 protected:
        /// Constructors
index 9ff8cea24dc08c310158927a63250eba7cdb3791..36507cf8e280b11aa8bbe8dcfc7d03b006a4fc98 100644 (file)
@@ -355,7 +355,8 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
        string maybeBeginL;
        string maybeEndL;
        bool needEndL = false;
-       if (!runparams.isFullUnicode() && runparams.local_font->isRightToLeft()) {
+       if (!runparams.isFullUnicode()
+           && runparams.local_font && runparams.local_font->isRightToLeft()) {
                maybeBeginL = "\\beginL";
                maybeEndL = "\\endL";
        }
index e711feebf4c6db3e397a2c441fcb48111cf5d0c4..3315d3b8968a1748c88a3df2760b914b56a4dd6b 100644 (file)
@@ -195,11 +195,11 @@ docstring InsetFloatList::xhtml(XMLStream &, OutputParams const & op) const {
                if (type == "table") {
                        toctype = "table";
                        toclabel = translateIfPossible(from_ascii("List of Tables"),
-                                                      op.local_font->language()->lang());
+                                                      getLocalOrDefaultLang(op)->lang());
                } else if (type == "figure") {
                        toctype = "figure";
                        toclabel = translateIfPossible(from_ascii("List of Figures"),
-                                                      op.local_font->language()->lang());
+                                                      getLocalOrDefaultLang(op)->lang());
                } else {
                        LYXERR0("Unknown Builtin Float!");
                        return docstring();
@@ -207,7 +207,7 @@ docstring InsetFloatList::xhtml(XMLStream &, OutputParams const & op) const {
        } else {
                toctype = to_utf8(getParam("type"));
                toclabel = translateIfPossible(from_utf8(cit->second.listName()),
-                                              op.local_font->language()->lang());
+                                              getLocalOrDefaultLang(op)->lang());
        }
 
        shared_ptr<Toc const> toc = buffer().tocBackend().toc(toctype);
index b20b553a786873fb1b53e369d408f1aaae18ff33..67f932ed9758264cdbf72eedeb79a7ef5e2f546f 100644 (file)
@@ -1911,7 +1911,7 @@ docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const
        xs << xml::StartTag("div", tocattr);
        xs << xml::CR();
        xs << xml::StartTag(lay.htmltag(), lay.htmlGetAttrString());
-       xs << translateIfPossible(indexName, op.local_font->language()->lang());
+       xs << translateIfPossible(indexName, getLocalOrDefaultLang(op)->lang());
        xs << xml::EndTag(lay.htmltag());
        xs << xml::CR();
        xs << xml::StartTag("ul", "class='main'");
index bd619862432c0b525698eaa54c06347c26cd5679..8268cebd68c0d0d52748ada0c08aad4908ac1e69 100644 (file)
@@ -187,7 +187,8 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
                if (!basicstyle.empty())
                        param_string = rtrim(param_string, ",") + ",basicstyle={" + basicstyle + "}";
        }
-       if (runparams.use_polyglossia && runparams.local_font->isRightToLeft()) {
+       if (runparams.use_polyglossia && runparams.local_font
+           && runparams.local_font->isRightToLeft()) {
                // We need to use the *latin switches (#11554)
                smatch sub;
                if (regex_match(param_string, sub, reg1))
@@ -248,9 +249,7 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
        Encoding const * const save_enc = runparams.encoding;
 
        Encoding const * const outer_encoding =
-               (runparams.local_font != 0) ?
-                       runparams.local_font->language()->encoding()
-                       : buffer().params().language->encoding();
+               getLocalOrDefaultLang(runparams)->encoding();
        Encoding const * fixedlstenc = forcedEncoding(runparams.encoding, outer_encoding);
        if (fixedlstenc) {
                // We need to switch to a singlebyte encoding, due to
index 1d77826602497d3368268498770be2329ea64a04..1d2ceb33181749c8b8dd23f451687f8541abcaac 100644 (file)
@@ -222,7 +222,7 @@ docstring InsetPrintNomencl::xhtml(XMLStream &, OutputParams const & op) const
        InsetLayout const & il = getLayout();
        string const & tag = il.htmltag();
        docstring toclabel = translateIfPossible(from_ascii("Nomenclature"),
-               op.local_font->language()->lang());
+               getLocalOrDefaultLang(op)->lang());
 
        xs << xml::StartTag("div", "class='nomencl'")
           << xml::StartTag(tag, "class='nomencl'")
@@ -333,7 +333,7 @@ void InsetPrintNomencl::docbook(XMLStream & xs, OutputParams const & runparams)
        // TODO: At least, that's what was done before...
 
        docstring toclabel = translateIfPossible(from_ascii("Nomenclature"),
-                                                                                        runparams.local_font->language()->lang());
+                                                getLocalOrDefaultLang(runparams)->lang());
 
        xs << xml::StartTag("glossary");
        xs << xml::CR();
index 53709daba438074a0228087077ebf8d230162527..46b8ef11ae6c87c261e36529c769d96c4447020d 100644 (file)
@@ -814,7 +814,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
                 || style == QuoteStyle::French
                 || style == QuoteStyle::FrenchIN)
                 && level_ == QuoteLevel::Primary
-                && prefixIs(runparams.local_font->language()->code(), "fr")) {
+                && prefixIs(getLocalOrDefaultLang(runparams)->code(), "fr")) {
                // Specific guillemets of French babel
                // including correct French spacing
                if (side_ == QuoteSide::Opening)
@@ -826,11 +826,11 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const
                // (ligatures not featured in PDF strings)
                qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
        } else if (runparams.main_fontenc == "T1"
-                  && !runparams.local_font->language()->internalFontEncoding()) {
+                  && !getLocalOrDefaultLang(runparams)->internalFontEncoding()) {
                // Quotation marks for T1 font encoding
                // (using ligatures)
                qstr = quoteparams.getLaTeXQuote(quotechar, "t1");
-       } else if (runparams.local_font->language()->internalFontEncoding()) {
+       } else if (getLocalOrDefaultLang(runparams)->internalFontEncoding()) {
                // Quotation marks for internal font encodings
                // (ligatures not featured)
                qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
index 746b9ea870f3d9018841ce4c3e801cc69951008b..c8bc837a5f4d50b0ec74dd843fe87d12426aed16 100644 (file)
@@ -432,7 +432,7 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
        // some sort of counter with the label, and we don't have that yet.
        docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"';
        xs << xml::StartTag("a", to_utf8(attr));
-       xs << displayString(ref, cmd, op.local_font->language()->lang());;
+       xs << displayString(ref, cmd, getLocalOrDefaultLang(op)->lang());
        xs << xml::EndTag("a");
        return docstring();
 }
index 0e0b9b6aacb598158570418d1b985fff9ad017d9..53fda518dad65fd28bfe89f998ea21e1a0b5904f 100644 (file)
@@ -588,8 +588,7 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
        case InsetSpaceParams::PROTECTED:
                if (runparams.find_effective())
                        os.put(0xa0);
-               else if (runparams.local_font
-                        && runparams.local_font->language()->lang() == "polutonikogreek")
+               else if (getLocalOrDefaultLang(runparams)->lang() == "polutonikogreek")
                        // in babel's polutonikogreek, ~ is active
                        os << (runparams.free_spacing ? " " : "\\nobreakspace{}");
                else
index f930ed7b678451df0c9ed3d5575d88e7d35687ee..a1f7fec332837ad177fc99448c7d0fd0354c1f9d 100644 (file)
@@ -421,15 +421,15 @@ void InsetSpecialChar::read(Lexer & lex)
 void InsetSpecialChar::latex(otexstream & os,
                             OutputParams const & rp) const
 {
-       bool const rtl = rp.local_font->isRightToLeft();
+       bool const rtl = rp.local_font && rp.local_font->isRightToLeft();
        bool const utf8 = rp.encoding->iconvName() == "UTF-8";
        string lswitch = "";
        string lswitche = "";
        if (rtl && !rp.use_polyglossia) {
                lswitch = "\\L{";
                lswitche = "}";
-               if (rp.local_font->language()->lang() == "arabic_arabi"
-                   || rp.local_font->language()->lang() == "farsi")
+               if (getLocalOrDefaultLang(rp)->lang() == "arabic_arabi"
+                   || getLocalOrDefaultLang(rp)->lang() == "farsi")
                        lswitch = "\\textLR{";
        }
 
index e8fc1baf97398638e33181593954e0c941c68c1a..6572dfe52abaa61588e998c965822a60523e73fd 100644 (file)
@@ -3179,7 +3179,8 @@ void Tabular::TeXRow(otexstream & os, row_type row,
        // The bidi package (loaded by polyglossia with XeTeX) reverses RTL table columns
        // Luabibdi (used by LuaTeX) behaves like classic
        bool const bidi_rtl =
-               runparams.local_font->isRightToLeft()
+               runparams.local_font
+               && runparams.local_font->isRightToLeft()
                && buffer().params().useBidiPackage(runparams);
        bool const ct = !buffer().params().output_changes;
        idx_type lastcell =
@@ -3351,7 +3352,8 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
        // The bidi package (loaded by polyglossia with XeTeX) swaps the column
        // order for RTL (#9686). Thus we use this list.
        bool const bidi_rtl =
-               runparams.local_font->isRightToLeft()
+               runparams.local_font
+               && runparams.local_font->isRightToLeft()
                && buffer().params().useBidiPackage(runparams);
        list<col_type> columns;
        list<col_type> logical_columns;