goo/GooString.h | 3 poppler/Annot.cc | 147 ++++++++++++++----------------------- poppler/DateInfo.cc | 4 - poppler/Form.cc | 52 +++++-------- poppler/Form.h | 4 - poppler/JSInfo.cc | 4 - poppler/Outline.cc | 4 - poppler/TextOutputDev.cc | 2 poppler/UTF.cc | 22 ++--- poppler/UTF.h | 6 - qt5/tests/check_utf_conversion.cpp | 16 ++-- qt6/tests/check_utf_conversion.cpp | 16 ++-- utils/pdfinfo.cc | 2 utils/pdfsig.cc | 4 - 14 files changed, 121 insertions(+), 165 deletions(-)
New commits: commit 406c83c465ddae11d98dcd2f9033b0cd0b262255 Author: Albert Astals Cid <[email protected]> Date: Fri Oct 29 15:09:27 2021 +0200 FormFieldText::tokenizeDA: Return a vector of strings instead of a vector of pointers Makes it for simpler memory management diff --git a/poppler/Annot.cc b/poppler/Annot.cc index fbfad5ff..74ad0e7e 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -800,35 +800,32 @@ DefaultAppearance::DefaultAppearance(const GooString *da) fontPtSize = -1; if (da) { - std::vector<GooString *> daToks; + std::vector<std::string> daToks; int i = FormFieldText::tokenizeDA(da->toStr(), &daToks, "Tf"); if (i >= 1) { - fontPtSize = gatof(daToks[i - 1]->c_str()); + fontPtSize = gatof(daToks[i - 1].c_str()); } if (i >= 2) { // We are expecting a name, therefore the first letter should be '/'. - const GooString *fontToken = daToks[i - 2]; - if (fontToken && fontToken->getLength() > 1 && fontToken->getChar(0) == '/') { + const std::string &fontToken = daToks[i - 2]; + if (fontToken.size() > 1 && fontToken[0] == '/') { // The +1 is here to skip the leading '/'. - fontName = Object(objName, fontToken->c_str() + 1); + fontName = Object(objName, fontToken.c_str() + 1); } } // Scan backwards: we are looking for the last set value for (i = daToks.size() - 1; i >= 0; --i) { if (!fontColor) { - if (!(daToks[i])->cmp("g") && i >= 1) { - fontColor = std::make_unique<AnnotColor>(gatof((daToks[i - 1])->c_str())); - } else if (!(daToks[i])->cmp("rg") && i >= 3) { - fontColor = std::make_unique<AnnotColor>(gatof((daToks[i - 3])->c_str()), gatof((daToks[i - 2])->c_str()), gatof((daToks[i - 1])->c_str())); - } else if (!(daToks[i])->cmp("k") && i >= 4) { - fontColor = std::make_unique<AnnotColor>(gatof((daToks[i - 4])->c_str()), gatof((daToks[i - 3])->c_str()), gatof((daToks[i - 2])->c_str()), gatof((daToks[i - 1])->c_str())); + if (daToks[i] == "g" && i >= 1) { + fontColor = std::make_unique<AnnotColor>(gatof(daToks[i - 1].c_str())); + } else if (daToks[i] == "rg" && i >= 3) { + fontColor = std::make_unique<AnnotColor>(gatof(daToks[i - 3].c_str()), gatof(daToks[i - 2].c_str()), gatof(daToks[i - 1].c_str())); + } else if (daToks[i] == "k" && i >= 4) { + fontColor = std::make_unique<AnnotColor>(gatof(daToks[i - 4].c_str()), gatof(daToks[i - 3].c_str()), gatof(daToks[i - 2].c_str()), gatof(daToks[i - 1].c_str())); } } } - for (auto entry : daToks) { - delete entry; - } } } diff --git a/poppler/Form.cc b/poppler/Form.cc index 35ea5156..fe39d3cb 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -1562,57 +1562,46 @@ void FormFieldText::reset(const std::vector<std::string> &excludedFields) double FormFieldText::getTextFontSize() { - std::vector<GooString *> daToks; + std::vector<std::string> daToks; int idx = parseDA(&daToks); double fontSize = -1; if (idx >= 0) { char *p = nullptr; - fontSize = strtod(daToks[idx]->c_str(), &p); + fontSize = strtod(daToks[idx].c_str(), &p); if (!p || *p) fontSize = -1; } - for (auto entry : daToks) { - delete entry; - } return fontSize; } void FormFieldText::setTextFontSize(int fontSize) { if (fontSize > 0 && obj.isDict()) { - std::vector<GooString *> *daToks = new std::vector<GooString *>(); - int idx = parseDA(daToks); + std::vector<std::string> daToks; + int idx = parseDA(&daToks); if (idx == -1) { error(errSyntaxError, -1, "FormFieldText:: invalid DA object\n"); - for (auto entry : *daToks) { - delete entry; - } - delete daToks; return; } if (defaultAppearance) delete defaultAppearance; defaultAppearance = new GooString; - for (std::size_t i = 0; i < daToks->size(); ++i) { + for (std::size_t i = 0; i < daToks.size(); ++i) { if (i > 0) defaultAppearance->append(' '); if (i == (std::size_t)idx) { defaultAppearance->appendf("{0:d}", fontSize); } else { - defaultAppearance->append((*daToks)[i]); + defaultAppearance->append(daToks[i]); } } - for (auto entry : *daToks) { - delete entry; - } - delete daToks; obj.dictSet("DA", Object(defaultAppearance->copy())); xref->setModifiedObject(&obj, ref); updateChildrenAppearance(); } } -int FormFieldText::tokenizeDA(const std::string &da, std::vector<GooString *> *daToks, const char *searchTok) +int FormFieldText::tokenizeDA(const std::string &da, std::vector<std::string> *daToks, const char *searchTok) { int idx = -1; if (daToks) { @@ -1624,10 +1613,10 @@ int FormFieldText::tokenizeDA(const std::string &da, std::vector<GooString *> *d } if (i < da.size()) { for (j = i + 1; j < da.size() && !Lexer::isSpace(da[j]); ++j) { } - GooString *tok = new GooString(da, i, j - i); - if (searchTok && !tok->cmp(searchTok)) + std::string tok(da, i, j - i); + if (searchTok && tok == searchTok) idx = daToks->size(); - daToks->push_back(tok); + daToks->emplace_back(std::move(tok)); i = j; } } @@ -1635,7 +1624,7 @@ int FormFieldText::tokenizeDA(const std::string &da, std::vector<GooString *> *d return idx; } -int FormFieldText::parseDA(std::vector<GooString *> *daToks) +int FormFieldText::parseDA(std::vector<std::string> *daToks) { int idx = -1; if (obj.isDict()) { diff --git a/poppler/Form.h b/poppler/Form.h index 6ecff357..d88f0a0a 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -496,10 +496,10 @@ public: void print(int indent) override; void reset(const std::vector<std::string> &excludedFields) override; - static int tokenizeDA(const std::string &daString, std::vector<GooString *> *daToks, const char *searchTok); + static int tokenizeDA(const std::string &daString, std::vector<std::string> *daToks, const char *searchTok); protected: - int parseDA(std::vector<GooString *> *daToks); + int parseDA(std::vector<std::string> *daToks); void fillContent(FillValueType fillType); GooString *content; commit aba39d21302dcf53af6961cf6739c510532c683c Author: Albert Astals Cid <[email protected]> Date: Fri Oct 29 14:52:03 2021 +0200 No need to new a vector that we always end deleting later diff --git a/poppler/Annot.cc b/poppler/Annot.cc index bfdef091..fbfad5ff 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -800,36 +800,35 @@ DefaultAppearance::DefaultAppearance(const GooString *da) fontPtSize = -1; if (da) { - std::vector<GooString *> *daToks = new std::vector<GooString *>(); - int i = FormFieldText::tokenizeDA(da->toStr(), daToks, "Tf"); + std::vector<GooString *> daToks; + int i = FormFieldText::tokenizeDA(da->toStr(), &daToks, "Tf"); if (i >= 1) { - fontPtSize = gatof((*daToks)[i - 1]->c_str()); + fontPtSize = gatof(daToks[i - 1]->c_str()); } if (i >= 2) { // We are expecting a name, therefore the first letter should be '/'. - const GooString *fontToken = (*daToks)[i - 2]; + const GooString *fontToken = daToks[i - 2]; if (fontToken && fontToken->getLength() > 1 && fontToken->getChar(0) == '/') { // The +1 is here to skip the leading '/'. fontName = Object(objName, fontToken->c_str() + 1); } } // Scan backwards: we are looking for the last set value - for (i = daToks->size() - 1; i >= 0; --i) { + for (i = daToks.size() - 1; i >= 0; --i) { if (!fontColor) { - if (!((*daToks)[i])->cmp("g") && i >= 1) { - fontColor = std::make_unique<AnnotColor>(gatof(((*daToks)[i - 1])->c_str())); - } else if (!((*daToks)[i])->cmp("rg") && i >= 3) { - fontColor = std::make_unique<AnnotColor>(gatof(((*daToks)[i - 3])->c_str()), gatof(((*daToks)[i - 2])->c_str()), gatof(((*daToks)[i - 1])->c_str())); - } else if (!((*daToks)[i])->cmp("k") && i >= 4) { - fontColor = std::make_unique<AnnotColor>(gatof(((*daToks)[i - 4])->c_str()), gatof(((*daToks)[i - 3])->c_str()), gatof(((*daToks)[i - 2])->c_str()), gatof(((*daToks)[i - 1])->c_str())); + if (!(daToks[i])->cmp("g") && i >= 1) { + fontColor = std::make_unique<AnnotColor>(gatof((daToks[i - 1])->c_str())); + } else if (!(daToks[i])->cmp("rg") && i >= 3) { + fontColor = std::make_unique<AnnotColor>(gatof((daToks[i - 3])->c_str()), gatof((daToks[i - 2])->c_str()), gatof((daToks[i - 1])->c_str())); + } else if (!(daToks[i])->cmp("k") && i >= 4) { + fontColor = std::make_unique<AnnotColor>(gatof((daToks[i - 4])->c_str()), gatof((daToks[i - 3])->c_str()), gatof((daToks[i - 2])->c_str()), gatof((daToks[i - 1])->c_str())); } } } - for (auto entry : *daToks) { + for (auto entry : daToks) { delete entry; } - delete daToks; } } @@ -4168,7 +4167,7 @@ void AnnotAppearanceBuilder::writeString(const GooString &str) bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da, const GfxResources *resources, const AnnotBorder *border, const AnnotAppearanceCharacs *appearCharacs, const PDFRectangle *rect, bool multiline, int comb, int quadding, bool txField, bool forceZapfDingbats, XRef *xref, bool password, Dict *resourcesDict, const char *defaultFallback) { - std::vector<GooString *> *daToks; + std::vector<GooString *> daToks; GooString *tok; GooString convertedText; const GfxFont *font; @@ -4186,7 +4185,6 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // parse the default appearance string tfPos = tmPos = -1; if (da) { - daToks = new std::vector<GooString *>(); int i = 0; while (i < da->getLength()) { while (i < da->getLength() && Lexer::isSpace(da->getChar(i))) { @@ -4195,26 +4193,24 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da if (i < da->getLength()) { for (j = i + 1; j < da->getLength() && !Lexer::isSpace(da->getChar(j)); ++j) ; - daToks->push_back(new GooString(da, i, j - i)); + daToks.push_back(new GooString(da, i, j - i)); i = j; } } - for (i = 2; i < (int)daToks->size(); ++i) { - if (i >= 2 && !((*daToks)[i])->cmp("Tf")) { + for (i = 2; i < (int)daToks.size(); ++i) { + if (i >= 2 && !(daToks[i])->cmp("Tf")) { tfPos = i - 2; - } else if (i >= 6 && !((*daToks)[i])->cmp("Tm")) { + } else if (i >= 6 && !(daToks[i])->cmp("Tm")) { tmPos = i - 6; } } - } else { - daToks = nullptr; } // get the font and font size font = nullptr; fontSize = 0; if (tfPos >= 0) { - tok = (*daToks)[tfPos]; + tok = daToks[tfPos]; if (forceZapfDingbats) { assert(xref != nullptr); if (tok->cmp("/ZaDb")) { @@ -4235,17 +4231,14 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da } else { error(errSyntaxError, -1, "Invalid font name in 'Tf' operator in field's DA string"); } - tok = (*daToks)[tfPos + 1]; + tok = daToks[tfPos + 1]; fontSize = gatof(tok->c_str()); } else { error(errSyntaxError, -1, "Missing 'Tf' operator in field's DA string"); } if (!font) { - if (daToks) { - for (auto entry : *daToks) { - delete entry; - } - delete daToks; + for (auto entry : daToks) { + delete entry; } return false; } @@ -4317,7 +4310,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da } } if (tfPos >= 0) { - tok = (*daToks)[tfPos + 1]; + tok = daToks[tfPos + 1]; tok->clear(); tok->appendf("{0:.2f}", fontSize); } @@ -4330,19 +4323,17 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // set the font matrix if (tmPos >= 0) { - tok = (*daToks)[tmPos + 4]; + tok = daToks[tmPos + 4]; tok->clear(); tok->append('0'); - tok = (*daToks)[tmPos + 5]; + tok = daToks[tmPos + 5]; tok->clear(); tok->appendf("{0:.2f}", y); } // write the DA string - if (daToks) { - for (const GooString *daTok : *daToks) { - appearBuf->append(daTok)->append(' '); - } + for (const GooString *daTok : daToks) { + appearBuf->append(daTok)->append(' '); } // write the font matrix (if not part of the DA string) @@ -4399,7 +4390,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da } fontSize = floor(fontSize); if (tfPos >= 0) { - tok = (*daToks)[tfPos + 1]; + tok = daToks[tfPos + 1]; tok->clear(); tok->appendf("{0:.2f}", fontSize); } @@ -4427,19 +4418,17 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // set the font matrix if (tmPos >= 0) { - tok = (*daToks)[tmPos + 4]; + tok = daToks[tmPos + 4]; tok->clear(); tok->appendf("{0:.2f}", x); - tok = (*daToks)[tmPos + 5]; + tok = daToks[tmPos + 5]; tok->clear(); tok->appendf("{0:.2f}", y); } // write the DA string - if (daToks) { - for (i = 0; i < (int)daToks->size(); ++i) { - appearBuf->append((*daToks)[i])->append(' '); - } + for (i = 0; i < (int)daToks.size(); ++i) { + appearBuf->append(daToks[i])->append(' '); } // write the font matrix (if not part of the DA string) @@ -4494,7 +4483,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da } fontSize = floor(fontSize); if (tfPos >= 0) { - tok = (*daToks)[tfPos + 1]; + tok = daToks[tfPos + 1]; tok->clear(); tok->appendf("{0:.2f}", fontSize); } @@ -4518,19 +4507,17 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // set the font matrix if (tmPos >= 0) { - tok = (*daToks)[tmPos + 4]; + tok = daToks[tmPos + 4]; tok->clear(); tok->appendf("{0:.2f}", x); - tok = (*daToks)[tmPos + 5]; + tok = daToks[tmPos + 5]; tok->clear(); tok->appendf("{0:.2f}", y); } // write the DA string - if (daToks) { - for (const GooString *daTok : *daToks) { - appearBuf->append(daTok)->append(' '); - } + for (const GooString *daTok : daToks) { + appearBuf->append(daTok)->append(' '); } // write the font matrix (if not part of the DA string) @@ -4549,11 +4536,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da if (txField) { appearBuf->append("EMC\n"); } - if (daToks) { - for (auto entry : *daToks) { - delete entry; - } - delete daToks; + for (auto entry : daToks) { + delete entry; } if (freeText) { delete text; @@ -4568,7 +4552,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da // Draw the variable text or caption for a field. bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect, const GooString *da, const GfxResources *resources, int quadding, XRef *xref, Dict *resourcesDict) { - std::vector<GooString *> *daToks; + std::vector<GooString *> daToks; GooString *tok; GooString convertedText; const GfxFont *font; @@ -4583,7 +4567,6 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con // parse the default appearance string tfPos = tmPos = -1; if (da) { - daToks = new std::vector<GooString *>(); i = 0; while (i < da->getLength()) { while (i < da->getLength() && Lexer::isSpace(da->getChar(i))) { @@ -4592,26 +4575,24 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con if (i < da->getLength()) { for (j = i + 1; j < da->getLength() && !Lexer::isSpace(da->getChar(j)); ++j) ; - daToks->push_back(new GooString(da, i, j - i)); + daToks.push_back(new GooString(da, i, j - i)); i = j; } } - for (std::size_t k = 2; k < daToks->size(); ++k) { - if (k >= 2 && !((*daToks)[k])->cmp("Tf")) { + for (std::size_t k = 2; k < daToks.size(); ++k) { + if (k >= 2 && !(daToks[k])->cmp("Tf")) { tfPos = k - 2; - } else if (k >= 6 && !((*daToks)[k])->cmp("Tm")) { + } else if (k >= 6 && !(daToks[k])->cmp("Tm")) { tmPos = k - 6; } } - } else { - daToks = nullptr; } // get the font and font size font = nullptr; fontSize = 0; if (tfPos >= 0) { - tok = (*daToks)[tfPos]; + tok = daToks[tfPos]; if (tok->getLength() >= 1 && tok->getChar(0) == '/') { if (!resources || !(font = resources->lookupFont(tok->c_str() + 1))) { if (xref != nullptr && resourcesDict != nullptr) { @@ -4625,17 +4606,14 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con } else { error(errSyntaxError, -1, "Invalid font name in 'Tf' operator in field's DA string"); } - tok = (*daToks)[tfPos + 1]; + tok = daToks[tfPos + 1]; fontSize = gatof(tok->c_str()); } else { error(errSyntaxError, -1, "Missing 'Tf' operator in field's DA string"); } if (!font) { - if (daToks) { - for (auto entry : *daToks) { - delete entry; - } - delete daToks; + for (auto entry : daToks) { + delete entry; } return false; } @@ -4650,11 +4628,8 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con j = 0; if (fieldChoice->getChoice(i) == nullptr) { error(errSyntaxError, -1, "Invalid annotation listbox"); - if (daToks) { - for (auto entry : *daToks) { - delete entry; - } - delete daToks; + for (auto entry : daToks) { + delete entry; } if (fontToFree) { fontToFree->decRefCnt(); @@ -4673,7 +4648,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con } fontSize = floor(fontSize); if (tfPos >= 0) { - tok = (*daToks)[tfPos + 1]; + tok = daToks[tfPos + 1]; tok->clear(); tok->appendf("{0:.2f}", fontSize); } @@ -4712,19 +4687,17 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con // set the font matrix if (tmPos >= 0) { - tok = (*daToks)[tmPos + 4]; + tok = daToks[tmPos + 4]; tok->clear(); tok->appendf("{0:.2f}", x); - tok = (*daToks)[tmPos + 5]; + tok = daToks[tmPos + 5]; tok->clear(); tok->appendf("{0:.2f}", y); } // write the DA string - if (daToks) { - for (const GooString *daTok : *daToks) { - appearBuf->append(daTok)->append(' '); - } + for (const GooString *daTok : daToks) { + appearBuf->append(daTok)->append(' '); } // write the font matrix (if not part of the DA string) @@ -4749,11 +4722,8 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con y -= 1.1 * fontSize; } - if (daToks) { - for (auto entry : *daToks) { - delete entry; - } - delete daToks; + for (auto entry : daToks) { + delete entry; } if (fontToFree) { fontToFree->decRefCnt(); diff --git a/poppler/Form.cc b/poppler/Form.cc index 04c677b6..35ea5156 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -1562,19 +1562,18 @@ void FormFieldText::reset(const std::vector<std::string> &excludedFields) double FormFieldText::getTextFontSize() { - std::vector<GooString *> *daToks = new std::vector<GooString *>(); - int idx = parseDA(daToks); + std::vector<GooString *> daToks; + int idx = parseDA(&daToks); double fontSize = -1; if (idx >= 0) { char *p = nullptr; - fontSize = strtod((*daToks)[idx]->c_str(), &p); + fontSize = strtod(daToks[idx]->c_str(), &p); if (!p || *p) fontSize = -1; } - for (auto entry : *daToks) { + for (auto entry : daToks) { delete entry; } - delete daToks; return fontSize; } commit 94d9d102f77312d808b7b65112d0a530a7ca4a12 Author: Albert Astals Cid <[email protected]> Date: Fri Oct 29 14:34:13 2021 +0200 Port a few functions from GooString to std::string diff --git a/goo/GooString.h b/goo/GooString.h index 81c2d5b7..aa68635c 100644 --- a/goo/GooString.h +++ b/goo/GooString.h @@ -17,7 +17,7 @@ // // Copyright (C) 2006 Kristian Høgsberg <[email protected]> // Copyright (C) 2006 Krzysztof Kowalczyk <[email protected]> -// Copyright (C) 2008-2010, 2012, 2014, 2017-2020 Albert Astals Cid <[email protected]> +// Copyright (C) 2008-2010, 2012, 2014, 2017-2021 Albert Astals Cid <[email protected]> // Copyright (C) 2012-2014 Fabio D'Urso <[email protected]> // Copyright (C) 2013 Jason Crain <[email protected]> // Copyright (C) 2015, 2018 Adam Reichold <[email protected]> @@ -80,6 +80,7 @@ public: // Create a string from <lengthA> chars at <idx> in <str>. GooString(const GooString *str, int idx, int lengthA) : std::string(*str, idx, lengthA) { } + GooString(const std::string &str, int idx, int lengthA) : std::string(str, idx, lengthA) { } // Set content of a string to <newStr>. GooString *Set(const GooString *newStr) diff --git a/poppler/Annot.cc b/poppler/Annot.cc index caf64f53..bfdef091 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -801,7 +801,7 @@ DefaultAppearance::DefaultAppearance(const GooString *da) if (da) { std::vector<GooString *> *daToks = new std::vector<GooString *>(); - int i = FormFieldText::tokenizeDA(da, daToks, "Tf"); + int i = FormFieldText::tokenizeDA(da->toStr(), daToks, "Tf"); if (i >= 1) { fontPtSize = gatof((*daToks)[i - 1]->c_str()); diff --git a/poppler/DateInfo.cc b/poppler/DateInfo.cc index 1e6b51c6..177f80cf 100644 --- a/poppler/DateInfo.cc +++ b/poppler/DateInfo.cc @@ -2,7 +2,7 @@ // // DateInfo.cc // -// Copyright (C) 2008, 2018, 2019 Albert Astals Cid <[email protected]> +// Copyright (C) 2008, 2018, 2019, 2021 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Carlos Garcia Campos <[email protected]> // Copyright (C) 2015 André Guerreiro <[email protected]> // Copyright (C) 2015 André Esser <[email protected]> @@ -37,7 +37,7 @@ bool parseDateString(const GooString *date, int *year, int *month, int *day, int *hour, int *minute, int *second, char *tz, int *tzHour, int *tzMinute) { Unicode *u; - int len = TextStringToUCS4(date, &u); + int len = TextStringToUCS4(date->toStr(), &u); GooString s; for (int i = 0; i < len; i++) { // Ignore any non ASCII characters diff --git a/poppler/Form.cc b/poppler/Form.cc index 8b0159a6..04c677b6 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -1613,18 +1613,18 @@ void FormFieldText::setTextFontSize(int fontSize) } } -int FormFieldText::tokenizeDA(const GooString *da, std::vector<GooString *> *daToks, const char *searchTok) +int FormFieldText::tokenizeDA(const std::string &da, std::vector<GooString *> *daToks, const char *searchTok) { int idx = -1; - if (da && daToks) { - int i = 0; - int j = 0; - while (i < da->getLength()) { - while (i < da->getLength() && Lexer::isSpace(da->getChar(i))) { + if (daToks) { + size_t i = 0; + size_t j = 0; + while (i < da.size()) { + while (i < da.size() && Lexer::isSpace(da[i])) { ++i; } - if (i < da->getLength()) { - for (j = i + 1; j < da->getLength() && !Lexer::isSpace(da->getChar(j)); ++j) { } + if (i < da.size()) { + for (j = i + 1; j < da.size() && !Lexer::isSpace(da[j]); ++j) { } GooString *tok = new GooString(da, i, j - i); if (searchTok && !tok->cmp(searchTok)) idx = daToks->size(); @@ -1643,7 +1643,7 @@ int FormFieldText::parseDA(std::vector<GooString *> *daToks) Object objDA(obj.dictLookup("DA")); if (objDA.isString()) { const GooString *da = objDA.getString(); - idx = tokenizeDA(da, daToks, "Tf") - 1; + idx = tokenizeDA(da->toStr(), daToks, "Tf") - 1; } } return idx; diff --git a/poppler/Form.h b/poppler/Form.h index 9c51bcfd..6ecff357 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -496,7 +496,7 @@ public: void print(int indent) override; void reset(const std::vector<std::string> &excludedFields) override; - static int tokenizeDA(const GooString *daString, std::vector<GooString *> *daToks, const char *searchTok); + static int tokenizeDA(const std::string &daString, std::vector<GooString *> *daToks, const char *searchTok); protected: int parseDA(std::vector<GooString *> *daToks); diff --git a/poppler/JSInfo.cc b/poppler/JSInfo.cc index eb11a9ce..97625633 100644 --- a/poppler/JSInfo.cc +++ b/poppler/JSInfo.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2013 Adrian Johnson <[email protected]> -// Copyright (C) 2017, 2020 Albert Astals Cid <[email protected]> +// Copyright (C) 2017, 2020, 2021 Albert Astals Cid <[email protected]> // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2020 Oliver Sander <[email protected]> // Copyright (C) 2020 Nelson Benítez León <[email protected]> @@ -45,7 +45,7 @@ void JSInfo::printJS(const GooString *js) if (!js || !js->c_str()) return; - len = TextStringToUCS4(js, &u); + len = TextStringToUCS4(js->toStr(), &u); for (i = 0; i < len; i++) { n = uniMap->mapUnicode(u[i], buf, sizeof(buf)); fwrite(buf, 1, n, file); diff --git a/poppler/Outline.cc b/poppler/Outline.cc index aa6b4ef9..268dcaf3 100644 --- a/poppler/Outline.cc +++ b/poppler/Outline.cc @@ -413,7 +413,7 @@ OutlineItem::OutlineItem(const Dict *dict, Ref refA, OutlineItem *parentA, XRef obj1 = dict->lookup("Title"); if (obj1.isString()) { const GooString *s = obj1.getString(); - titleLen = TextStringToUCS4(s, &title); + titleLen = TextStringToUCS4(s->toStr(), &title); } else { titleLen = 0; } @@ -494,7 +494,7 @@ void OutlineItem::setTitle(const std::string &titleA) Object dict = xref->fetch(ref); GooString *g = new GooString(titleA); - titleLen = TextStringToUCS4(g, &title); + titleLen = TextStringToUCS4(g->toStr(), &title); dict.dictSet("Title", Object(g)); xref->setModifiedObject(&dict, ref); } diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc index 633d1392..c0929033 100644 --- a/poppler/TextOutputDev.cc +++ b/poppler/TextOutputDev.cc @@ -5618,7 +5618,7 @@ void ActualText::end(const GfxState *state) // now that we have the position info for all of the text inside // the marked content span, we feed the "ActualText" back through // text->addChar() - length = TextStringToUCS4(actualText, &uni); + length = TextStringToUCS4(actualText->toStr(), &uni); text->addChar(state, actualTextX0, actualTextY0, actualTextX1 - actualTextX0, actualTextY1 - actualTextY0, 0, actualTextNBytes, uni, length); gfree(uni); } diff --git a/poppler/UTF.cc b/poppler/UTF.cc index fadd833f..8dd972c7 100644 --- a/poppler/UTF.cc +++ b/poppler/UTF.cc @@ -16,7 +16,7 @@ // Copyright (C) 2008 Koji Otani <[email protected]> // Copyright (C) 2012, 2017, 2021 Adrian Johnson <[email protected]> // Copyright (C) 2012 Hib Eris <[email protected]> -// Copyright (C) 2016, 2018-2020 Albert Astals Cid <[email protected]> +// Copyright (C) 2016, 2018-2021 Albert Astals Cid <[email protected]> // Copyright (C) 2016 Jason Crain <[email protected]> // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018, 2020 Nelson Benítez León <[email protected]> @@ -88,24 +88,24 @@ int UTF16toUCS4(const Unicode *utf16, int utf16Len, Unicode **ucs4_out) return len; } -int TextStringToUCS4(const GooString *textStr, Unicode **ucs4) +int TextStringToUCS4(const std::string &textStr, Unicode **ucs4) { int i, len; const char *s; Unicode *u; bool isUnicode, isUnicodeLE; - len = textStr->getLength(); - s = textStr->c_str(); + len = textStr.size(); + s = textStr.c_str(); if (len == 0) { *ucs4 = nullptr; return 0; } - if (textStr->hasUnicodeMarker()) { + if (GooString::hasUnicodeMarker(textStr)) { isUnicode = true; isUnicodeLE = false; - } else if (textStr->hasUnicodeMarkerLE()) { + } else if (GooString::hasUnicodeMarkerLE(textStr)) { isUnicode = false; isUnicodeLE = true; } else { @@ -357,10 +357,10 @@ uint16_t *utf8ToUtf16(const char *utf8, int *len) return utf16; } -GooString *utf8ToUtf16WithBom(const GooString &utf8) +GooString *utf8ToUtf16WithBom(const std::string &utf8) { GooString *result = new GooString(); - if (utf8.toStr().empty()) { + if (utf8.empty()) { return result; } int tmp_length; // Number of UTF-16 symbols. @@ -515,7 +515,7 @@ void unicodeToAscii7(const Unicode *in, int len, Unicode **ucs4_out, int *out_le idx = (int *)gmallocn(len * 8 + 1, sizeof(int)); } - GooString gstr; + std::string str; char buf[8]; // 8 is enough for mapping an unicode char to a string int i, n, k; @@ -528,14 +528,14 @@ void unicodeToAscii7(const Unicode *in, int len, Unicode **ucs4_out, int *out_le buf[0] = 31; n = 1; } - gstr.append(buf, n); + str.append(buf, n); if (indices) { for (; n > 0; n--) idx[k++] = in_idx[i]; } } - *out_len = TextStringToUCS4(&gstr, ucs4_out); + *out_len = TextStringToUCS4(str, ucs4_out); if (indices) { idx[k] = in_idx[len]; diff --git a/poppler/UTF.h b/poppler/UTF.h index 0a85a0e2..5dca83e4 100644 --- a/poppler/UTF.h +++ b/poppler/UTF.h @@ -8,7 +8,7 @@ // Copyright (C) 2016 Jason Crain <[email protected]> // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Nelson Benítez León <[email protected]> -// Copyright (C) 2019, 2020 Albert Astals Cid <[email protected]> +// Copyright (C) 2019-2021 Albert Astals Cid <[email protected]> // Copyright (C) 2021 Georgiy Sgibnev <[email protected]>. Work sponsored by lab50.net. // //======================================================================== @@ -35,7 +35,7 @@ int UTF16toUCS4(const Unicode *utf16, int utf16Len, Unicode **ucs4_out); // ucs4 - if the number of UCS-4 characters is > 0, allocates and // returns UCS-4 string. Free with gfree. // returns number of UCS-4 characters -int POPPLER_PRIVATE_EXPORT TextStringToUCS4(const GooString *textStr, Unicode **ucs4); +int POPPLER_PRIVATE_EXPORT TextStringToUCS4(const std::string &textStr, Unicode **ucs4); // check if UCS-4 character is valid bool UnicodeIsValid(Unicode ucs4); @@ -76,7 +76,7 @@ uint16_t POPPLER_PRIVATE_EXPORT *utf8ToUtf16(const char *utf8, int *len = nullpt // The caller owns the returned pointer. // utf8 - UTF-8 string to convert. An empty string is acceptable. // Returns a big endian UTF-16 string with BOM or an empty string without BOM. -GooString POPPLER_PRIVATE_EXPORT *utf8ToUtf16WithBom(const GooString &utf8); +GooString POPPLER_PRIVATE_EXPORT *utf8ToUtf16WithBom(const std::string &utf8); // Count number of UTF-8 bytes required to convert a UTF-16 string to // UTF-8 (excluding terminating NULL). diff --git a/qt5/tests/check_utf_conversion.cpp b/qt5/tests/check_utf_conversion.cpp index 4df1ca51..0d1a20a1 100644 --- a/qt5/tests/check_utf_conversion.cpp +++ b/qt5/tests/check_utf_conversion.cpp @@ -99,8 +99,8 @@ void TestUTFConversion::testUTF() QVERIFY(compare(utf16String, s.utf16())); free(utf16String); - GooString gsUtf8(str); - std::unique_ptr<GooString> gsUtf16_a(utf8ToUtf16WithBom(gsUtf8)); + std::string sUtf8(str); + std::unique_ptr<GooString> gsUtf16_a(utf8ToUtf16WithBom(sUtf8)); std::unique_ptr<GooString> gsUtf16_b(Poppler::QStringToUnicodeGooString(s)); QCOMPARE(gsUtf16_a->cmp(gsUtf16_b.get()), 0); @@ -131,7 +131,7 @@ void TestUTFConversion::testUnicodeToAscii7() GooString *goo = Poppler::QStringToUnicodeGooString(QString::fromUtf8("®©©©©©©©©©©©©©©©©©©©©")); // clazy:exclude=qstring-allocations Unicode *in; - const int in_len = TextStringToUCS4(goo, &in); + const int in_len = TextStringToUCS4(goo->toStr(), &in); delete goo; @@ -163,17 +163,17 @@ void TestUTFConversion::testUnicodeToAscii7() void TestUTFConversion::testUnicodeLittleEndian() { uint16_t UTF16LE_hi[5] { 0xFFFE, 0x4800, 0x4900, 0x2100, 0x1126 }; // UTF16-LE "HI!☑" - GooString GooUTF16LE(reinterpret_cast<const char *>(UTF16LE_hi), sizeof(UTF16LE_hi)); + std::string GooUTF16LE(reinterpret_cast<const char *>(UTF16LE_hi), sizeof(UTF16LE_hi)); uint16_t UTF16BE_hi[5] { 0xFEFF, 0x0048, 0x0049, 0x0021, 0x2611 }; // UTF16-BE "HI!☑" - GooString GooUTF16BE(reinterpret_cast<const char *>(UTF16BE_hi), sizeof(UTF16BE_hi)); + std::string GooUTF16BE(reinterpret_cast<const char *>(UTF16BE_hi), sizeof(UTF16BE_hi)); // Let's assert both GooString's are different - QVERIFY(GooUTF16LE.cmp(&GooUTF16BE)); + QVERIFY(GooUTF16LE != GooUTF16BE); Unicode *UCS4fromLE, *UCS4fromBE; - const int len1 = TextStringToUCS4(&GooUTF16LE, &UCS4fromLE); - const int len2 = TextStringToUCS4(&GooUTF16BE, &UCS4fromBE); + const int len1 = TextStringToUCS4(GooUTF16LE, &UCS4fromLE); + const int len2 = TextStringToUCS4(GooUTF16BE, &UCS4fromBE); // len is 4 because TextStringToUCS4() removes the two leading Byte Order Mark (BOM) code points QCOMPARE(len1, len2); diff --git a/qt6/tests/check_utf_conversion.cpp b/qt6/tests/check_utf_conversion.cpp index f3110922..c4d3f8db 100644 --- a/qt6/tests/check_utf_conversion.cpp +++ b/qt6/tests/check_utf_conversion.cpp @@ -97,8 +97,8 @@ void TestUTFConversion::testUTF() QVERIFY(compare(utf16String, s.utf16())); free(utf16String); - GooString gsUtf8(str); - std::unique_ptr<GooString> gsUtf16_a(utf8ToUtf16WithBom(gsUtf8)); + std::string sUtf8(str); + std::unique_ptr<GooString> gsUtf16_a(utf8ToUtf16WithBom(sUtf8)); std::unique_ptr<GooString> gsUtf16_b(Poppler::QStringToUnicodeGooString(s)); QCOMPARE(gsUtf16_a->cmp(gsUtf16_b.get()), 0); @@ -129,7 +129,7 @@ void TestUTFConversion::testUnicodeToAscii7() GooString *goo = Poppler::QStringToUnicodeGooString(QString::fromUtf8("®©©©©©©©©©©©©©©©©©©©©")); // clazy:exclude=qstring-allocations Unicode *in; - const int in_len = TextStringToUCS4(goo, &in); + const int in_len = TextStringToUCS4(goo->toStr(), &in); delete goo; @@ -161,17 +161,17 @@ void TestUTFConversion::testUnicodeToAscii7() void TestUTFConversion::testUnicodeLittleEndian() { uint16_t UTF16LE_hi[5] { 0xFFFE, 0x4800, 0x4900, 0x2100, 0x1126 }; // UTF16-LE "HI!☑" - GooString GooUTF16LE(reinterpret_cast<const char *>(UTF16LE_hi), sizeof(UTF16LE_hi)); + std::string GooUTF16LE(reinterpret_cast<const char *>(UTF16LE_hi), sizeof(UTF16LE_hi)); uint16_t UTF16BE_hi[5] { 0xFEFF, 0x0048, 0x0049, 0x0021, 0x2611 }; // UTF16-BE "HI!☑" - GooString GooUTF16BE(reinterpret_cast<const char *>(UTF16BE_hi), sizeof(UTF16BE_hi)); + std::string GooUTF16BE(reinterpret_cast<const char *>(UTF16BE_hi), sizeof(UTF16BE_hi)); // Let's assert both GooString's are different - QVERIFY(GooUTF16LE.cmp(&GooUTF16BE)); + QVERIFY(GooUTF16LE != GooUTF16BE); Unicode *UCS4fromLE, *UCS4fromBE; - const int len1 = TextStringToUCS4(&GooUTF16LE, &UCS4fromLE); - const int len2 = TextStringToUCS4(&GooUTF16BE, &UCS4fromBE); + const int len1 = TextStringToUCS4(GooUTF16LE, &UCS4fromLE); + const int len2 = TextStringToUCS4(GooUTF16BE, &UCS4fromBE); // len is 4 because TextStringToUCS4() removes the two leading Byte Order Mark (BOM) code points QCOMPARE(len1, len2); diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc index d47b2564..8e9e26fd 100644 --- a/utils/pdfinfo.cc +++ b/utils/pdfinfo.cc @@ -116,7 +116,7 @@ static void printTextString(const GooString *s, const UnicodeMap *uMap) { Unicode *u; char buf[8]; - int len = TextStringToUCS4(s, &u); + int len = TextStringToUCS4(s->toStr(), &u); for (int i = 0; i < len; i++) { int n = uMap->mapUnicode(u[i], buf, sizeof(buf)); fwrite(buf, 1, n, stdout); diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc index 2f370d26..a1579478 100644 --- a/utils/pdfsig.cc +++ b/utils/pdfsig.cc @@ -314,7 +314,7 @@ int main(int argc, char *argv[]) } const char *pw = (strlen(password) == 0) ? nullptr : password; - const auto rs = std::unique_ptr<GooString>(reason.toStr().empty() ? nullptr : utf8ToUtf16WithBom(reason)); + const auto rs = std::unique_ptr<GooString>(reason.toStr().empty() ? nullptr : utf8ToUtf16WithBom(reason.toStr())); if (newSignatureFieldName.getLength() == 0) { // Create a random field name, it could be anything but 32 hex numbers should @@ -365,7 +365,7 @@ int main(int argc, char *argv[]) if (etsiCAdESdetached) ffs->setSignatureType(ETSI_CAdES_detached); const char *pw = (strlen(password) == 0) ? nullptr : password; - const auto rs = std::unique_ptr<GooString>(reason.toStr().empty() ? nullptr : utf8ToUtf16WithBom(reason)); + const auto rs = std::unique_ptr<GooString>(reason.toStr().empty() ? nullptr : utf8ToUtf16WithBom(reason.toStr())); if (ffs->getNumWidgets() != 1) { printf("Unexpected number of widgets for the signature: %d\n", ffs->getNumWidgets()); return 2;
