[poppler] utils/HtmlFonts.cc utils/HtmlFonts.h utils/HtmlOutputDev.cc utils/pdftohtml.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Oct 7 17:13:44 UTC 2018
utils/HtmlFonts.cc | 135 ++++++++++++++++++-------------------------------
utils/HtmlFonts.h | 8 --
utils/HtmlOutputDev.cc | 6 --
utils/pdftohtml.cc | 1
4 files changed, 53 insertions(+), 97 deletions(-)
New commits:
commit e0eb2474ef0a154001512b66b7cd34f9d0cddd60
Author: Adam Reichold <adam.reichold at t-online.de>
Date: Tue Aug 21 20:09:40 2018 +0200
Remove HtmlFont::pos and always track a font name to allow handling of unknown font families with known style suffixes.
diff --git a/utils/HtmlFonts.cc b/utils/HtmlFonts.cc
index 9f0bc674..afd7a2a9 100644
--- a/utils/HtmlFonts.cc
+++ b/utils/HtmlFonts.cc
@@ -42,36 +42,37 @@
#include "GfxFont.h"
#include <stdio.h>
- struct Fonts{
- const char *Fontname;
- const char *name;
- };
-
-const int font_num=13;
-
-static Fonts fonts[font_num+1]={
- {"Courier", "Courier" },
- {"Courier-Bold", "Courier"},
- {"Courier-BoldOblique", "Courier"},
- {"Courier-Oblique", "Courier"},
- {"Helvetica", "Helvetica"},
- {"Helvetica-Bold", "Helvetica"},
- {"Helvetica-BoldOblique", "Helvetica"},
- {"Helvetica-Oblique", "Helvetica"},
- {"Symbol", "Symbol" },
- {"Times-Bold", "Times" },
- {"Times-BoldItalic", "Times" },
- {"Times-Italic", "Times" },
- {"Times-Roman", "Times" },
- {" " , "Times" },
+namespace
+{
+
+const char* const defaultFamilyName = "Times";
+
+const char* const styleSuffixes[] = {
+ "-Regular",
+ "-Bold",
+ "-BoldOblique",
+ "-BoldItalic",
+ "-Oblique",
+ "-Italic",
+ "-Roman",
};
+void removeStyleSuffix(std::string& familyName) {
+ for (const char* const styleSuffix : styleSuffixes) {
+ auto pos = familyName.rfind(styleSuffix);
+ if (pos != std::string::npos) {
+ familyName.resize(pos);
+ return;
+ }
+ }
+}
+
+}
+
#define xoutRound(x) ((int)(x + 0.5))
extern GBool xml;
extern GBool fontFullName;
-GooString* HtmlFont::DefaultFont=new GooString("Times"); // Arial,Helvetica,sans-serif
-
HtmlFontColor::HtmlFontColor(GfxRGB rgb){
r=static_cast<int>(rgb.r/65535.0*255.0);
g=static_cast<int>(rgb.g/65535.0*255.0);
@@ -110,23 +111,8 @@ GooString *HtmlFontColor::toString() const{
}
HtmlFont::HtmlFont(GfxFont *font, int _size, GfxRGB rgb){
- //if (col) color=HtmlFontColor(col);
- //else color=HtmlFontColor();
color=HtmlFontColor(rgb);
- const GooString* ftname=font->getName();
- if (!ftname) ftname = getDefaultFont();
- GooString *fontname = nullptr;
-
- if( ftname ){
- fontname = new GooString(ftname);
- FontName=new GooString(ftname);
- }
- else {
- fontname = nullptr;
- FontName = nullptr;
- }
-
lineSize = -1;
size=(_size-1);
@@ -137,27 +123,28 @@ HtmlFont::HtmlFont(GfxFont *font, int _size, GfxRGB rgb){
if (font->isBold() || font->getWeight() >= GfxFont::W700) bold=gTrue;
if (font->isItalic()) italic=gTrue;
- if (fontname){
- if (!bold && strstr(fontname->lowerCase()->getCString(),"bold")) {
+ if (const GooString *fontname = font->getName()){
+ FontName = new GooString(fontname);
+
+ GooString fontnameLower(fontname);
+ fontnameLower.lowerCase();
+
+ if (!bold && strstr(fontnameLower.getCString(),"bold")) {
bold=gTrue;
}
if (!italic &&
- (strstr(fontname->lowerCase()->getCString(),"italic")||
- strstr(fontname->lowerCase()->getCString(),"oblique"))) {
+ (strstr(fontnameLower.getCString(),"italic")||
+ strstr(fontnameLower.getCString(),"oblique"))) {
italic=gTrue;
}
- int i=0;
- while (strcmp(ftname->getCString(),fonts[i].Fontname)&&(i<font_num))
- {
- i++;
- }
- pos=i;
- delete fontname;
- } else
- pos = font_num;
- if (!DefaultFont) DefaultFont=new GooString(fonts[font_num].name);
+ familyName = fontname->getCString();
+ removeStyleSuffix(familyName);
+ } else {
+ FontName = new GooString(defaultFamilyName);
+ familyName = defaultFamilyName;
+ }
rotSkewMat[0] = rotSkewMat[1] = rotSkewMat[2] = rotSkewMat[3] = 0;
}
@@ -167,16 +154,16 @@ HtmlFont::HtmlFont(const HtmlFont& x){
lineSize=x.lineSize;
italic=x.italic;
bold=x.bold;
- pos=x.pos;
+ familyName=x.familyName;
color=x.color;
- FontName = (x.FontName) ? new GooString(x.FontName) : nullptr;
+ FontName=new GooString(x.FontName);
rotOrSkewed = x.rotOrSkewed;
memcpy(rotSkewMat, x.rotSkewMat, sizeof(rotSkewMat));
}
HtmlFont::~HtmlFont(){
- if (FontName) delete FontName;
+ delete FontName;
}
HtmlFont& HtmlFont::operator=(const HtmlFont& x){
@@ -185,20 +172,13 @@ HtmlFont& HtmlFont::operator=(const HtmlFont& x){
lineSize=x.lineSize;
italic=x.italic;
bold=x.bold;
- pos=x.pos;
+ familyName=x.familyName;
color=x.color;
- if (FontName) delete FontName;
- FontName = (x.FontName) ? new GooString(x.FontName) : nullptr;
+ delete FontName;
+ FontName=new GooString(x.FontName);
return *this;
}
-void HtmlFont::clear(){
- if(DefaultFont) delete DefaultFont;
- DefaultFont = nullptr;
-}
-
-
-
/*
This function is used to compare font uniquely for insertion into
the list of all encountered fonts
@@ -206,7 +186,7 @@ void HtmlFont::clear(){
GBool HtmlFont::isEqual(const HtmlFont& x) const{
return (size==x.size) &&
(lineSize==x.lineSize) &&
- (pos==x.pos) && (bold==x.bold) && (italic==x.italic) &&
+ (FontName->cmp(x.FontName) == 0) && (bold==x.bold) && (italic==x.italic) &&
(color.isEqual(x.getColor())) && isRotOrSkewed() == x.isRotOrSkewed() &&
(!isRotOrSkewed() || rot_matrices_equal(getRotMat(), x.getRotMat()));
}
@@ -217,29 +197,16 @@ GBool HtmlFont::isEqual(const HtmlFont& x) const{
*/
GBool HtmlFont::isEqualIgnoreBold(const HtmlFont& x) const{
return ((size==x.size) &&
- (!strcmp(fonts[pos].name, fonts[x.pos].name)) &&
+ (familyName == x.familyName) &&
(color.isEqual(x.getColor())));
}
GooString* HtmlFont::getFontName(){
- if (pos!=font_num) return new GooString(fonts[pos].name);
- else return new GooString(DefaultFont);
+ return new GooString(familyName);
}
GooString* HtmlFont::getFullName(){
- if (FontName)
- return new GooString(FontName);
- else return new GooString(DefaultFont);
-}
-
-void HtmlFont::setDefaultFont(GooString* defaultFont){
- if (DefaultFont) delete DefaultFont;
- DefaultFont=new GooString(defaultFont);
-}
-
-
-GooString* HtmlFont::getDefaultFont(){
- return DefaultFont;
+ return new GooString(FontName);
}
// this method if plain wrong todo
@@ -381,7 +348,7 @@ GooString* HtmlFontAccu::CSStyle(int i, int j){
tmp->append("\" size=\"");
tmp->append(Size);
tmp->append("\" family=\"");
- tmp->append(fontName); //font.getFontName());
+ tmp->append(fontName);
tmp->append("\" color=\"");
tmp->append(colorStr);
tmp->append("\"/>");
diff --git a/utils/HtmlFonts.h b/utils/HtmlFonts.h
index ba4f42ae..26abb7bf 100644
--- a/utils/HtmlFonts.h
+++ b/utils/HtmlFonts.h
@@ -65,8 +65,7 @@ class HtmlFont{
GBool italic;
GBool bold;
GBool rotOrSkewed;
- int pos; // position of the font name in the fonts array
- static GooString *DefaultFont;
+ std::string familyName;
GooString *FontName;
HtmlFontColor color;
double rotSkewMat[4]; // only four values needed for rotation and skew
@@ -77,7 +76,6 @@ public:
HtmlFont& operator=(const HtmlFont& x);
HtmlFontColor getColor() const {return color;}
~HtmlFont();
- static void clear();
GooString* getFullName();
GBool isItalic() const {return italic;}
GBool isBold() const {return bold;}
@@ -89,13 +87,11 @@ public:
{ rotOrSkewed = gTrue; memcpy(rotSkewMat, mat, sizeof(rotSkewMat)); }
const double *getRotMat() const { return rotSkewMat; }
GooString* getFontName();
- static GooString* getDefaultFont();
- static void setDefaultFont(GooString* defaultFont);
static GooString* HtmlFilter(const Unicode* u, int uLen); //char* s);
GBool isEqual(const HtmlFont& x) const;
GBool isEqualIgnoreBold(const HtmlFont& x) const;
static GooString* simple(HtmlFont *font, Unicode *content, int uLen);
- void print() const {printf("font: %s %d %s%spos: %d\n", FontName->getCString(), size, bold ? "bold " : "", italic ? "italic " : "", pos);};
+ void print() const {printf("font: %s (%s) %d %s%s\n", FontName->getCString(), familyName.c_str(), size, bold ? "bold " : "", italic ? "italic " : "");};
};
class HtmlFontAccu{
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index df3171db..b379102b 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -352,7 +352,6 @@ void HtmlPage::conv(){
HtmlFont* h;
for(tmp=yxStrings;tmp;tmp=tmp->yxNext){
int pos=tmp->fontpos;
- // printf("%d\n",pos);
h=fonts->Get(pos);
if (tmp->htext) delete tmp->htext;
@@ -360,9 +359,6 @@ void HtmlPage::conv(){
if (links->inLink(tmp->xMin,tmp->yMin,tmp->xMax,tmp->yMax, linkIndex)){
tmp->link = links->getLink(linkIndex);
- /*GooString *t=tmp->htext;
- tmp->htext=links->getLink(k)->Link(tmp->htext);
- delete t;*/
}
}
@@ -1225,8 +1221,6 @@ HtmlOutputDev::HtmlOutputDev(Catalog *catalogA, const char *fileName, const char
}
HtmlOutputDev::~HtmlOutputDev() {
- HtmlFont::clear();
-
delete Docname;
delete docTitle;
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index a8ede422..6871f4e9 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -446,7 +446,6 @@ int main(int argc, char *argv[]) {
if(globalParams) delete globalParams;
if(htmlFileName) delete htmlFileName;
- HtmlFont::clear();
return exit_status;
}
More information about the poppler
mailing list