summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport/wrapper/wrapper.cxx
diff options
context:
space:
mode:
authorKevin Suo <suokunlong@126.com>2021-10-10 21:25:58 +0800
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-10-11 09:07:59 +0200
commit4eef83dc4a8879f21ee6c98226510ac728bc317a (patch)
tree4237f4446eb1288acb74bbe66cc51047dc58c114 /sdext/source/pdfimport/wrapper/wrapper.cxx
parentf60214a1ad45f947d063e4cfdbeb86bd819ab87c (diff)
sdext.pdfimport tdf#78427: Add support for more Font Weight features
...e.g. Thin, Extra-Light, Light, Semi-Bold, Bold, Extra-Bold and Black. Previously the xpdfimport code passes the isBold value which is bool value. sdext.pdfimport accepted this value from the xpdfimport output and check whether a font is bold or not. However, there are many other FontWeight features more than a "bold". This patch changes the isBold to the GfxFont::Weight type, and changed the sdext.pdfimport isBold bool type (in FontAttributes) to an OUString fontWeight. The value for the fontWeight is set according to the GfxFont::Weight passed by xpdfimport, and then this fontWeight is passed to the ODF xml generation stage and used there directly. Now the Semibold and Light (as shown in the unittest file) can be currectly handled. However, for other weights the parseFontFamilyName still need to be updated, but before doing that I plan to refector this function as the current logic is very difficult for maintennance. Change-Id: If2ce5f0f41c83843d8a6aeb30134b3faf99ba877 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123339 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sdext/source/pdfimport/wrapper/wrapper.cxx')
-rw-r--r--sdext/source/pdfimport/wrapper/wrapper.cxx88
1 files changed, 73 insertions, 15 deletions
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index 2efdab6f8553..4de5a8516297 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -49,6 +49,7 @@
#include <com/sun/star/geometry/RealRectangle2D.hpp>
#include <com/sun/star/geometry/RealSize2D.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/awt/FontWeight.hpp>
#include <tools/diagnose_ex.h>
#include <basegfx/point/b2dpoint.hxx>
@@ -483,18 +484,28 @@ e.g., TimesNewRoman -> Times New Roman
*/
void LineParser::parseFontFamilyName( FontAttributes& rResult )
{
- SAL_INFO("sdext.pdfimport", "Processing " << rResult.familyName << " ---");
+ SAL_WARN("sdext.pdfimport", "Processing " << rResult.familyName << " ---");
rResult.familyName = rResult.familyName.trim();
for (const OUString& fontAttributesSuffix: fontAttributesSuffixes)
{
if ( rResult.familyName.endsWith(fontAttributesSuffix) )
{
rResult.familyName = rResult.familyName.replaceAll(fontAttributesSuffix, "");
- SAL_INFO("sdext.pdfimport", rResult.familyName);
- if (fontAttributesSuffix == "Bold")
+ SAL_WARN("sdext.pdfimport", rResult.familyName);
+ if (fontAttributesSuffix == u"Bold")
{
- rResult.isBold = true;
- } else if ( (fontAttributesSuffix == "Italic") or (fontAttributesSuffix == "Oblique") )
+ rResult.fontWeight = u"bold";
+ }
+ else if (fontAttributesSuffix == u"Semibold")
+ {
+ rResult.fontWeight = u"600";
+ }
+ else if (fontAttributesSuffix == u"Light")
+ {
+ rResult.fontWeight = u"300";
+ }
+
+ if ( (fontAttributesSuffix == "Italic") or (fontAttributesSuffix == "Oblique") )
{
rResult.isItalic = true;
}
@@ -506,20 +517,23 @@ void LineParser::readFont()
{
/*
xpdf line is like (separated by space):
- updateFont <FontID> <isEmbedded> <isBold> <isItalic> <isUnderline> <TransformedFontSize> <nEmbedSize> <FontName>
- updateFont 14 1 0 0 0 1200.000000 23068 TimesNewRomanPSMT
+ updateFont <FontID> <isEmbedded> <maFontWeight> <isItalic> <isUnderline> <TransformedFontSize> <nEmbedSize> <FontName>
+ updateFont 14 1 4 0 0 1200.000000 23068 TimesNewRomanPSMT
If nEmbedSize > 0, then a fontFile is followed as a stream.
*/
-
- OString aFontName;
sal_Int64 nFontID;
- sal_Int32 nIsEmbedded, nIsBold, nIsItalic, nIsUnderline, nFileLen;
+ sal_Int32 nIsEmbedded;
+ sal_Int32 nFontWeight;
+ sal_Int32 nIsItalic;
+ sal_Int32 nIsUnderline;
double nSize;
+ sal_Int32 nFileLen;
+ OString aFontName;
readInt64(nFontID); // read FontID
readInt32(nIsEmbedded); // read isEmbedded
- readInt32(nIsBold); // read isBold
+ readInt32(nFontWeight); // read maFontWeight, see GfxFont enum Weight
readInt32(nIsItalic); // read isItalic
readInt32(nIsUnderline);// read isUnderline
readDouble(nSize); // read TransformedFontSize
@@ -545,15 +559,36 @@ void LineParser::readFont()
return;
}
- // yet unknown font - get info and add to map
+ // The font is not yet in the map list - get info and add to map
+ OUString sFontWeight; // font weight name per ODF specifications
+ if (nFontWeight == 0 or nFontWeight == 4) // WeightNotDefined or W400, map to normal font
+ sFontWeight = u"normal";
+ else if (nFontWeight == 1) // W100, Thin
+ sFontWeight = u"100";
+ else if (nFontWeight == 2) // W200, Extra-Light
+ sFontWeight = u"200";
+ else if (nFontWeight == 3) // W300, Light
+ sFontWeight = u"300";
+ else if (nFontWeight == 5) // W500, Medium. Is this supported by ODF?
+ sFontWeight = u"500";
+ else if (nFontWeight == 6) // W600, Semi-Bold
+ sFontWeight = u"600";
+ else if (nFontWeight == 7) // W700, Bold
+ sFontWeight = u"bold";
+ else if (nFontWeight == 8) // W800, Extra-Bold
+ sFontWeight = u"800";
+ else if (nFontWeight == 9) // W900, Black
+ sFontWeight = u"900";
+ SAL_WARN("sdext.pdfimport", "Font weight passed from xpdfimport is: " << sFontWeight);
+
FontAttributes aResult( OStringToOUString( aFontName, RTL_TEXTENCODING_UTF8 ),
- nIsBold != 0,
+ sFontWeight,
nIsItalic != 0,
nIsUnderline != 0,
nSize,
1.0);
- /* The above font attributes (fontName, bold, italic) are based on
+ /* The above font attributes (fontName, fontWeight, italic) are based on
xpdf line output and may not be reliable. To get correct attributes,
we do the following:
1. Read the embedded font file and determine the attributes based on the
@@ -583,7 +618,9 @@ void LineParser::readFont()
aFontReadResult >>= aFontDescriptor;
if (!aFontDescriptor.Name.isEmpty())
{
+ // Family name
aResult.familyName = aFontDescriptor.Name;
+ SAL_INFO("sdext.pdfimport", aResult.familyName);
// tdf#143959: there are cases when the family name returned by font descriptor
// is like "AAAAAA+TimesNewRoman,Bold". In this case, use the font name
// determined by parseFontFamilyName instead, but still determine the font
@@ -593,7 +630,28 @@ void LineParser::readFont()
aResult.familyName = aResult.familyName.copy(7, aResult.familyName.getLength() - 7);
parseFontFamilyName(aResult);
}
- aResult.isBold = (aFontDescriptor.Weight > 100.0);
+
+ // Font weight
+ if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::THIN)
+ aResult.fontWeight = u"100";
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::ULTRALIGHT)
+ aResult.fontWeight = u"200";
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::LIGHT)
+ aResult.fontWeight = u"300";
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::SEMILIGHT)
+ aResult.fontWeight = u"350";
+ // no need to check "normal" here as this is default in nFontWeight above
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::SEMIBOLD)
+ aResult.fontWeight = u"600";
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::BOLD)
+ aResult.fontWeight = u"bold";
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::ULTRABOLD)
+ aResult.fontWeight = u"800";
+ else if (aFontDescriptor.Weight == com::sun::star::awt::FontWeight::BLACK)
+ aResult.fontWeight = u"900";
+ SAL_INFO("sdext.pdfimport", aResult.fontWeight);
+
+ // Italic
aResult.isItalic = (aFontDescriptor.Slant == awt::FontSlant_OBLIQUE ||
aFontDescriptor.Slant == awt::FontSlant_ITALIC);
} else