standard font handling

This commit is contained in:
Jakub Melka 2019-04-29 18:13:16 +02:00
parent 11cb52921e
commit 5318e0e465
3 changed files with 73 additions and 5 deletions

View File

@ -52,7 +52,7 @@ public:
/// Loads font from descriptor
/// \param descriptor Descriptor describing the font
QByteArray loadFont(const FontDescriptor* descriptor) const;
QByteArray loadFont(const FontDescriptor* descriptor, StandardFontType standardFontType) const;
private:
explicit PDFSystemFontInfoStorage();
@ -91,7 +91,7 @@ const PDFSystemFontInfoStorage* PDFSystemFontInfoStorage::getInstance()
return &instance;
}
QByteArray PDFSystemFontInfoStorage::loadFont(const FontDescriptor* descriptor) const
QByteArray PDFSystemFontInfoStorage::loadFont(const FontDescriptor* descriptor, StandardFontType standardFontType) const
{
QByteArray result;
@ -101,7 +101,50 @@ QByteArray PDFSystemFontInfoStorage::loadFont(const FontDescriptor* descriptor)
const BYTE lfItalic = (descriptor->italicAngle != 0.0 ? TRUE : FALSE);
// Exact match font face name
QString fontName = getFontPostscriptName(descriptor->fontName);
QString fontName;
switch (standardFontType)
{
case StandardFontType::TimesRoman:
case StandardFontType::TimesRomanBold:
case StandardFontType::TimesRomanItalics:
case StandardFontType::TimesRomanBoldItalics:
{
fontName = "TimesNewRoman";
break;
}
case StandardFontType::Helvetica:
case StandardFontType::HelveticaBold:
case StandardFontType::HelveticaOblique:
case StandardFontType::HelveticaBoldOblique:
{
fontName = "Arial";
break;
}
case StandardFontType::Courier:
case StandardFontType::CourierBold:
case StandardFontType::CourierOblique:
case StandardFontType::CourierBoldOblique:
{
fontName = "Courier";
break;
}
case StandardFontType::Symbol:
case StandardFontType::ZapfDingbats:
{
fontName = "Symbol";
break;
}
default:
{
fontName = getFontPostscriptName(descriptor->fontName);
break;
}
}
if (!fontName.isEmpty())
{
for (const FontInfo& fontInfo : m_fontInfos)
@ -558,8 +601,16 @@ PDFRealizedFontPointer PDFRealizedFont::createRealizedFont(PDFFontPointer font,
}
else
{
StandardFontType standardFontType = StandardFontType::Invalid;
if (font->getFontType() == FontType::Type1)
{
Q_ASSERT(dynamic_cast<const PDFType1Font*>(font.get()));
const PDFType1Font* type1Font = static_cast<const PDFType1Font*>(font.get());
standardFontType = type1Font->getStandardFontType();
}
const PDFSystemFontInfoStorage* fontStorage = PDFSystemFontInfoStorage::getInstance();
impl->m_systemFontData = fontStorage->loadFont(descriptor);
impl->m_systemFontData = fontStorage->loadFont(descriptor, standardFontType);
if (impl->m_systemFontData.isEmpty())
{

View File

@ -1507,6 +1507,13 @@ void PDFPageContentProcessor::operatorTextEnd()
{
throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Text object ended more than once."));
}
if (!m_textClippingPath.isEmpty())
{
QPainterPath clippingPath = m_graphicState.getCurrentTransformationMatrix().inverted().map(m_textClippingPath);
performClipping(clippingPath, clippingPath.fillRule());
m_textClippingPath = QPainterPath();
}
}
void PDFPageContentProcessor::operatorTextSetCharacterSpacing(PDFReal charSpacing)
@ -1760,7 +1767,6 @@ void PDFPageContentProcessor::drawText(const TextSequence& textSequence)
const bool fill = isTextRenderingModeFilled(textRenderingMode);
const bool stroke = isTextRenderingModeStroked(textRenderingMode);
const bool clipped = isTextRenderingModeClipped(textRenderingMode);
// TODO: Add Text Clipping
// TODO: Pouzit pravdepodobne sirky z widths array?
// Detect horizontal writing system
@ -1801,6 +1807,13 @@ void PDFPageContentProcessor::drawText(const TextSequence& textSequence)
QMatrix textRenderingMatrix = adjustMatrix * textMatrix;
QPainterPath transformedGlyph = textRenderingMatrix.map(glyphPath);
performPathPainting(transformedGlyph, stroke, fill, transformedGlyph.fillRule());
if (clipped)
{
// Clipping is enabled, we must transform to the device coordinates
QMatrix toDeviceSpaceTransform = textRenderingMatrix * m_graphicState.getCurrentTransformationMatrix();
m_textClippingPath = m_textClippingPath.united(toDeviceSpaceTransform.map(glyphPath));
}
}
}

View File

@ -597,6 +597,10 @@ private:
/// Actually realized physical font
PDFCachedItem<PDFRealizedFontPointer> m_realizedFont;
/// Actual clipping path obtained from text. Clipping path
/// is in device space coordinates.
QPainterPath m_textClippingPath;
};
} // namespace pdf