[poppler] 2 commits - goo/GooString.h utils/HtmlFonts.cc utils/HtmlOutputDev.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 20 22:20:01 UTC 2019


 goo/GooString.h        |    1 +
 utils/HtmlFonts.cc     |   21 ++++++---------------
 utils/HtmlOutputDev.cc |   49 +++++++++++++++++++------------------------------
 3 files changed, 26 insertions(+), 45 deletions(-)

New commits:
commit 7671892300b0044b85ba289a7afb32e640b5b07d
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Nov 18 21:07:35 2019 +0100

    Have more strings on the stack, rather than on the heap
    
    And replace some GooString with std::string while we're at it.

diff --git a/utils/HtmlFonts.cc b/utils/HtmlFonts.cc
index 5310121d..b16cb4cb 100644
--- a/utils/HtmlFonts.cc
+++ b/utils/HtmlFonts.cc
@@ -276,29 +276,23 @@ int HtmlFontAccu::AddFont(const HtmlFont& font){
 // get CSS font definition for font #i 
 GooString* HtmlFontAccu::CSStyle(int i, int j){
    GooString *tmp=new GooString();
-   GooString *iStr=new GooString(std::to_string(i));
-   GooString *jStr=new GooString(std::to_string(j));
 
    std::vector<HtmlFont>::iterator g=accu->begin();
    g+=i;
    HtmlFont font=*g;
-   GooString *Size=new GooString(std::to_string(font.getSize()));
    GooString *colorStr=font.getColor().toString();
    GooString *fontName=(fontFullName ? font.getFullName() : font.getFontName());
-   GooString *lSize;
    
    if(!xml){
      tmp->append(".ft");
-     tmp->append(jStr);
-     tmp->append(iStr);
+     tmp->append(std::to_string(j));
+     tmp->append(std::to_string(i));
      tmp->append("{font-size:");
-     tmp->append(Size);
+     tmp->append(std::to_string(font.getSize()));
      if( font.getLineSize() != -1 && font.getLineSize() != 0 )
      {
-	 lSize = new GooString(std::to_string(font.getLineSize()));
 	 tmp->append("px;line-height:");
-	 tmp->append(lSize);
-	 delete lSize;
+	 tmp->append(std::to_string(font.getLineSize()));
      }
      tmp->append("px;font-family:");
      tmp->append(fontName); //font.getFontName());
@@ -331,9 +325,9 @@ GooString* HtmlFontAccu::CSStyle(int i, int j){
    }
    if (xml) {
      tmp->append("<fontspec id=\"");
-     tmp->append(iStr);
+     tmp->append(std::to_string(i));
      tmp->append("\" size=\"");
-     tmp->append(Size);
+     tmp->append(std::to_string(font.getSize()));
      tmp->append("\" family=\"");
      tmp->append(fontName);
      tmp->append("\" color=\"");
@@ -343,9 +337,6 @@ GooString* HtmlFontAccu::CSStyle(int i, int j){
 
    delete fontName;
    delete colorStr;
-   delete jStr;
-   delete iStr;
-   delete Size;
    return tmp;
 }
  
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 306bb416..ca4d4aaa 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -810,39 +810,34 @@ static void printCSS(FILE *f)
 }
 
 int HtmlPage::dumpComplexHeaders(FILE * const file, FILE *& pageFile, int page) {
-  GooString* tmp;
 
   if( !noframes )
   {
-      GooString* pgNum=new GooString(std::to_string(page));
-      tmp = new GooString(DocName);
+      const std::string pgNum = std::to_string(page);
+      std::string pageFileName(DocName->toStr());
       if (!singleHtml){
-            tmp->append('-')->append(pgNum)->append(".html");
-            pageFile = fopen(tmp->c_str(), "w");
+            pageFileName += '-' + pgNum + ".html";
+            pageFile = fopen(pageFileName.c_str(), "w");
       } else {
-            tmp->append("-html")->append(".html");
-            pageFile = fopen(tmp->c_str(), "a");
+            pageFileName += "-html.html";
+            pageFile = fopen(pageFileName.c_str(), "a");
       }
-      delete pgNum;
+
       if (!pageFile) {
-	  error(errIO, -1, "Couldn't open html file '{0:t}'", tmp);
-	  delete tmp;
+	  error(errIO, -1, "Couldn't open html file '{0:t}'", pageFileName.c_str());
 	  return 1;
       } 
 
       if (!singleHtml)
         fprintf(pageFile,"%s\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"\" xml:lang=\"\">\n<head>\n<title>Page %d</title>\n\n", DOCTYPE, page);
       else
-        fprintf(pageFile,"%s\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"\" xml:lang=\"\">\n<head>\n<title>%s</title>\n\n", DOCTYPE, tmp->c_str());
-
-      delete tmp;
+        fprintf(pageFile,"%s\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"\" xml:lang=\"\">\n<head>\n<title>%s</title>\n\n", DOCTYPE, pageFileName.c_str());
 
-      GooString *htmlEncoding = HtmlOutputDev::mapEncodingToHtml(globalParams->getTextEncodingName());
+      const std::string htmlEncoding = HtmlOutputDev::mapEncodingToHtml(globalParams->getTextEncodingName())->toStr();
       if (!singleHtml)
-        fprintf(pageFile, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>\n", htmlEncoding->c_str());
+        fprintf(pageFile, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>\n", htmlEncoding.c_str());
       else
-        fprintf(pageFile, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>\n <br/>\n", htmlEncoding->c_str());
-      delete htmlEncoding;
+        fprintf(pageFile, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>\n <br/>\n", htmlEncoding.c_str());
   }
   else 
   {
@@ -1577,7 +1572,6 @@ GooString* HtmlOutputDev::getLinkDest(AnnotLink *link){
 
 	      delete dest;
 
-	      GooString *str=new GooString(std::to_string(destPage));
 	      /* 		complex 	simple
 	       	frames		file-4.html	files.html#4
 		noframes	file.html#4	file.html#4
@@ -1585,25 +1579,24 @@ GooString* HtmlOutputDev::getLinkDest(AnnotLink *link){
 	      if (noframes)
 	      {
 		  file->append(".html#");
-		  file->append(str);
+		  file->append(std::to_string(destPage));
 	      }
 	      else
 	      {
 	      	if( complexMode ) 
 		{
 		    file->append("-");
-		    file->append(str);
+		    file->append(std::to_string(destPage));
 		    file->append(".html");
 		}
 		else
 		{
 		    file->append("s.html#");
-		    file->append(str);
+		    file->append(std::to_string(destPage));
 		}
 	      }
 
 	      if (printCommands) printf(" link to page %d ",destPage);
-	      delete str;
 	      return file;
 	  }
 	  else 
@@ -1634,9 +1627,7 @@ GooString* HtmlOutputDev::getLinkDest(AnnotLink *link){
 		      file->append(".html");
 		  }
 		  file->append('#');
-		  GooString *pgNum = new GooString(std::to_string(destPage));
-		  file->append(pgNum);
-		  delete pgNum;
+		  file->append(std::to_string(destPage));
 	      }
 	  }
 	  if (printCommands && file) printf("filename %s\n",file->c_str());
@@ -1777,21 +1768,19 @@ bool HtmlOutputDev::newHtmlOutlineLevel(FILE *output, const std::vector<OutlineI
 				noframes	file.html#4	file.html#4
 				*/
 				linkName = new GooString(gbasename(Docname->c_str()));
-				GooString *str = new GooString(std::to_string(itemPage));
 				if (noframes) {
 					linkName->append(".html#");
-					linkName->append(str);
+					linkName->append(std::to_string(itemPage));
 				} else {
 					if( complexMode ) {
 						linkName->append("-");
-						linkName->append(str);
+						linkName->append(std::to_string(itemPage));
 						linkName->append(".html");
 					} else {
 						linkName->append("s.html#");
-						linkName->append(str);
+						linkName->append(std::to_string(itemPage));
 					}
 				}
-				delete str;
 		}
 
 		fputs("<li>",output);
commit d331bfe09816397d5f6c8ef9744c418bc6063fe9
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Nov 18 21:06:59 2019 +0100

    Allow to append a std::string
    
    This is helpful in situations that mix GooString and std::string.

diff --git a/goo/GooString.h b/goo/GooString.h
index 5fccbe83..16e83a26 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -139,6 +139,7 @@ public:
   // Append a character or string.
   GooString *append(char c) { push_back(c); return this; }
   GooString *append(const GooString *str) { static_cast<std::string&>(*this).append(*str); return this; }
+  GooString *append(const std::string& str) { static_cast<std::string&>(*this).append(str); return this; }
   GooString *append(const char *str) { static_cast<std::string&>(*this).append(str); return this; }
   GooString *append(const char *str, int lengthA) { static_cast<std::string&>(*this).append(str, lengthA); return this; }
 


More information about the poppler mailing list