[poppler] goo/GooString.h poppler/GlobalParams.cc poppler/GlobalParamsWin.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Oct 6 15:18:07 UTC 2018


 goo/GooString.h            |    1 -
 poppler/GlobalParams.cc    |   40 ++++++++++++++++++----------------------
 poppler/GlobalParamsWin.cc |    4 ++--
 3 files changed, 20 insertions(+), 25 deletions(-)

New commits:
commit 257e583fceea1e35f0162a1dbd961859add688f9
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Sep 23 02:55:09 2018 +0200

    Remove last use of non const GooString::getCString

diff --git a/goo/GooString.h b/goo/GooString.h
index 38f3bed9..1eca4bc3 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -120,7 +120,6 @@ public:
   int getLength() const { return length; }
 
   // Get C string.
-  char *getCString() { return s; }
   const char *getCString() const { return s; }
 
   // Get <i>th character.
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 0d47025f..3e8cc3c4 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -245,8 +245,8 @@ public:
 private:
 
 #ifdef _WIN32
-  SysFontInfo *makeWindowsFont(char *name, int fontNum,
-			       char *path);
+  SysFontInfo *makeWindowsFont(const char *name, int fontNum,
+			       const char *path);
 #endif
 
   GooList *fonts;			// [SysFontInfo]
@@ -712,24 +712,22 @@ static FcPattern *buildFcPattern(GfxFont *font, const GooString *base14Name)
       slant = -1,
       width = -1,
       spacing = -1;
-  bool deleteFamily = false;
-  char *family, *name, *modifiers;
+  const char *family;
   const char *start;
   FcPattern *p;
 
   // this is all heuristics will be overwritten if font had proper info
-  GooString copiedNameGooString(((base14Name == nullptr) ? font->getName() : base14Name)->getCString());
-  name = copiedNameGooString.getCString();
+  char *fontName = strdup(((base14Name == nullptr) ? font->getName() : base14Name)->getCString());
 
-  modifiers = strchr (name, ',');
+  const char *modifiers = strchr (fontName, ',');
   if (modifiers == nullptr)
-    modifiers = strchr (name, '-');
+    modifiers = strchr (fontName, '-');
 
   // remove the - from the names, for some reason, Fontconfig does not
   // understand "MS-Mincho" but does with "MS Mincho"
-  int len = strlen(name);
+  const int len = strlen(fontName);
   for (int i = 0; i < len; i++)
-    name[i] = (name[i] == '-' ? ' ' : name[i]);
+    fontName[i] = (fontName[i] == '-' ? ' ' : fontName[i]);
 
   start = nullptr;
   findModifier(modifiers, "Regular", &start);
@@ -751,14 +749,13 @@ static FcPattern *buildFcPattern(GfxFont *font, const GooString *base14Name)
   if (start) {
     // There have been "modifiers" in the name, crop them to obtain
     // the family name
-    family = new char[len+1];
-    strcpy(family, name);
-    int pos = (modifiers - name);
-    family[pos] = '\0';
-    deleteFamily = true;
+    family = strndup(fontName, modifiers - fontName);
+    free(fontName);
+    fontName = nullptr;
   }
   else {
-    family = name;
+    family = fontName;
+    fontName = nullptr;
   }
   
   // use font flags
@@ -769,13 +766,12 @@ static FcPattern *buildFcPattern(GfxFont *font, const GooString *base14Name)
   if (font->isItalic())
     slant = FC_SLANT_ITALIC;
   
+  bool freeFamily = true;
   // if the FontDescriptor specified a family name use it
   if (font->getFamily()) {
-    if (deleteFamily) {
-      delete[] family;
-      deleteFamily = false;
-    }
+    free((char*)family);
     family = font->getFamily()->getCString();
+    freeFamily = false;
   }
   
   // if the FontDescriptor specified a weight use it
@@ -819,8 +815,8 @@ static FcPattern *buildFcPattern(GfxFont *font, const GooString *base14Name)
   if (width != -1) FcPatternAddInteger(p, FC_WIDTH, width);
   if (spacing != -1) FcPatternAddInteger(p, FC_SPACING, spacing);
 
-  if (deleteFamily)
-    delete[] family;
+  if (freeFamily)
+    free((char*)family);
   return p;
 }
 #endif
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index 024ae63d..40f6a683 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -295,8 +295,8 @@ void SysFontList::scanWindowsFonts(GooString *winFontDir) {
   }
 }
 
-SysFontInfo *SysFontList::makeWindowsFont(char *name, int fontNum,
-					  char *path) {
+SysFontInfo *SysFontList::makeWindowsFont(const char *name, int fontNum,
+					  const char *path) {
   int n;
   GBool bold, italic, oblique, fixedWidth;
   GooString *s;


More information about the poppler mailing list