mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-03 02:37:41 +01:00
Editor plugin: WIP
This commit is contained in:
parent
b481b3afcc
commit
d255e27fd3
@ -564,9 +564,10 @@ QString PDFSystemFontInfoStorage::getFontPostscriptName(QString fontName)
|
||||
return fontName.remove(QChar(' ')).remove(QChar('-')).remove(QChar(',')).trimmed();
|
||||
}
|
||||
|
||||
PDFFont::PDFFont(CIDSystemInfo CIDSystemInfo, FontDescriptor fontDescriptor) :
|
||||
PDFFont::PDFFont(CIDSystemInfo CIDSystemInfo, QByteArray fontId, FontDescriptor fontDescriptor) :
|
||||
m_CIDSystemInfo(qMove(CIDSystemInfo)),
|
||||
m_fontDescriptor(qMove(fontDescriptor))
|
||||
m_fontDescriptor(qMove(fontDescriptor)),
|
||||
m_fontId(qMove(fontId))
|
||||
{
|
||||
|
||||
}
|
||||
@ -1284,7 +1285,12 @@ CIDSystemInfo PDFFont::readCIDSystemInfo(const PDFObject& cidSystemInfoObject, c
|
||||
return cidSystemInfo;
|
||||
}
|
||||
|
||||
PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* document)
|
||||
QByteArray PDFFont::getFontId() const
|
||||
{
|
||||
return m_fontId;
|
||||
}
|
||||
|
||||
PDFFontPointer PDFFont::createFont(const PDFObject& object, QByteArray fontId, const PDFDocument* document)
|
||||
{
|
||||
const PDFObject& dereferencedFontDictionary = document->getObject(object);
|
||||
if (!dereferencedFontDictionary.isDictionary())
|
||||
@ -1763,7 +1769,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
|
||||
toUnicodeCMap = PDFFontCMap::createFromData(decodedStream);
|
||||
}
|
||||
|
||||
return PDFFontPointer(new PDFType0Font(qMove(cidSystemInfo), qMove(fontDescriptor), qMove(cmap), qMove(toUnicodeCMap), qMove(cidToGidMapper), defaultWidth, qMove(advances)));
|
||||
return PDFFontPointer(new PDFType0Font(qMove(cidSystemInfo), qMove(fontId), qMove(fontDescriptor), qMove(cmap), qMove(toUnicodeCMap), qMove(cidToGidMapper), defaultWidth, qMove(advances)));
|
||||
}
|
||||
|
||||
case FontType::Type3:
|
||||
@ -1853,7 +1859,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
|
||||
}
|
||||
|
||||
std::vector<PDFReal> widthsF3 = fontLoader.readNumberArrayFromDictionary(fontDictionary, "Widths");
|
||||
return PDFFontPointer(new PDFType3Font(qMove(fontDescriptor), firstCharF3, lastCharF3, fontMatrix, qMove(characterContentStreams), qMove(widthsF3), document->getObject(fontDictionary->get("Resources")), qMove(toUnicodeCMap)));
|
||||
return PDFFontPointer(new PDFType3Font(qMove(fontDescriptor), qMove(fontId), firstCharF3, lastCharF3, fontMatrix, qMove(characterContentStreams), qMove(widthsF3), document->getObject(fontDictionary->get("Resources")), qMove(toUnicodeCMap)));
|
||||
}
|
||||
|
||||
default:
|
||||
@ -1867,10 +1873,10 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
|
||||
{
|
||||
case FontType::Type1:
|
||||
case FontType::MMType1:
|
||||
return PDFFontPointer(new PDFType1Font(fontType, qMove(cidSystemInfo), qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, standardFont, glyphIndexArray));
|
||||
return PDFFontPointer(new PDFType1Font(fontType, qMove(fontId), qMove(cidSystemInfo), qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, standardFont, glyphIndexArray));
|
||||
|
||||
case FontType::TrueType:
|
||||
return PDFFontPointer(new PDFTrueTypeFont(qMove(cidSystemInfo), qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, glyphIndexArray));
|
||||
return PDFFontPointer(new PDFTrueTypeFont(qMove(cidSystemInfo), qMove(fontId), qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encoding, simpleFontEncodingTable, glyphIndexArray));
|
||||
|
||||
default:
|
||||
{
|
||||
@ -1883,6 +1889,7 @@ PDFFontPointer PDFFont::createFont(const PDFObject& object, const PDFDocument* d
|
||||
}
|
||||
|
||||
PDFSimpleFont::PDFSimpleFont(CIDSystemInfo cidSystemInfo,
|
||||
QByteArray fontId,
|
||||
FontDescriptor fontDescriptor,
|
||||
QByteArray name,
|
||||
QByteArray baseFont,
|
||||
@ -1892,7 +1899,7 @@ PDFSimpleFont::PDFSimpleFont(CIDSystemInfo cidSystemInfo,
|
||||
PDFEncoding::Encoding encodingType,
|
||||
encoding::EncodingTable encoding,
|
||||
GlyphIndices glyphIndices) :
|
||||
PDFFont(qMove(cidSystemInfo), qMove(fontDescriptor)),
|
||||
PDFFont(qMove(cidSystemInfo), qMove(fontId), qMove(fontDescriptor)),
|
||||
m_name(qMove(name)),
|
||||
m_baseFont(qMove(baseFont)),
|
||||
m_firstChar(firstChar),
|
||||
@ -1976,6 +1983,7 @@ void PDFSimpleFont::dumpFontToTreeItem(ITreeFactory* treeFactory) const
|
||||
}
|
||||
|
||||
PDFType1Font::PDFType1Font(FontType fontType,
|
||||
QByteArray fontId,
|
||||
CIDSystemInfo cidSystemInfo,
|
||||
FontDescriptor fontDescriptor,
|
||||
QByteArray name,
|
||||
@ -1987,7 +1995,7 @@ PDFType1Font::PDFType1Font(FontType fontType,
|
||||
encoding::EncodingTable encoding,
|
||||
StandardFontType standardFontType,
|
||||
GlyphIndices glyphIndices) :
|
||||
PDFSimpleFont(qMove(cidSystemInfo), qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encodingType, encoding, glyphIndices),
|
||||
PDFSimpleFont(qMove(cidSystemInfo), qMove(fontId), qMove(fontDescriptor), qMove(name), qMove(baseFont), firstChar, lastChar, qMove(widths), encodingType, encoding, glyphIndices),
|
||||
m_fontType(fontType),
|
||||
m_standardFontType(standardFontType)
|
||||
{
|
||||
@ -2068,7 +2076,7 @@ void PDFFontCache::setDocument(const PDFModifiedDocument& document)
|
||||
}
|
||||
}
|
||||
|
||||
PDFFontPointer PDFFontCache::getFont(const PDFObject& fontObject) const
|
||||
PDFFontPointer PDFFontCache::getFont(const PDFObject& fontObject, const QByteArray& fontId) const
|
||||
{
|
||||
if (fontObject.isReference())
|
||||
{
|
||||
@ -2081,7 +2089,7 @@ PDFFontPointer PDFFontCache::getFont(const PDFObject& fontObject) const
|
||||
if (it == m_fontCache.cend())
|
||||
{
|
||||
// We must create the font
|
||||
PDFFontPointer font = PDFFont::createFont(fontObject, m_document);
|
||||
PDFFontPointer font = PDFFont::createFont(fontObject, fontId, m_document);
|
||||
|
||||
if (m_fontCacheShrinkDisabledObjects.empty() && m_fontCache.size() >= m_fontCacheLimit)
|
||||
{
|
||||
@ -2096,7 +2104,7 @@ PDFFontPointer PDFFontCache::getFont(const PDFObject& fontObject) const
|
||||
else
|
||||
{
|
||||
// Object is not a reference. Create font directly and return it.
|
||||
return PDFFont::createFont(fontObject, m_document);
|
||||
return PDFFont::createFont(fontObject, fontId, m_document);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2611,6 +2619,7 @@ PDFReal PDFType0Font::getGlyphAdvance(CID cid) const
|
||||
}
|
||||
|
||||
PDFType3Font::PDFType3Font(FontDescriptor fontDescriptor,
|
||||
QByteArray fontId,
|
||||
int firstCharacterIndex,
|
||||
int lastCharacterIndex,
|
||||
QTransform fontMatrix,
|
||||
@ -2618,7 +2627,7 @@ PDFType3Font::PDFType3Font(FontDescriptor fontDescriptor,
|
||||
std::vector<double>&& widths,
|
||||
const PDFObject& resources,
|
||||
PDFFontCMap toUnicode) :
|
||||
PDFFont(CIDSystemInfo(), qMove(fontDescriptor)),
|
||||
PDFFont(CIDSystemInfo(), qMove(fontId), qMove(fontDescriptor)),
|
||||
m_firstCharacterIndex(firstCharacterIndex),
|
||||
m_lastCharacterIndex(lastCharacterIndex),
|
||||
m_fontMatrix(fontMatrix),
|
||||
|
@ -295,7 +295,7 @@ private:
|
||||
class PDF4QTLIBCORESHARED_EXPORT PDFFont
|
||||
{
|
||||
public:
|
||||
explicit PDFFont(CIDSystemInfo CIDSystemInfo, FontDescriptor fontDescriptor);
|
||||
explicit PDFFont(CIDSystemInfo CIDSystemInfo, QByteArray fontId, FontDescriptor fontDescriptor);
|
||||
virtual ~PDFFont() = default;
|
||||
|
||||
/// Returns the font type
|
||||
@ -318,8 +318,9 @@ public:
|
||||
|
||||
/// Creates font from the object. If font can't be created, exception is thrown.
|
||||
/// \param object Font dictionary
|
||||
/// \param fontId Font ID
|
||||
/// \param document Document
|
||||
static PDFFontPointer createFont(const PDFObject& object, const PDFDocument* document);
|
||||
static PDFFontPointer createFont(const PDFObject& object, QByteArray fontId, const PDFDocument* document);
|
||||
|
||||
/// Tries to read font descriptor from the object
|
||||
/// \param fontDescriptorObject Font descriptor dictionary
|
||||
@ -331,9 +332,13 @@ public:
|
||||
/// \param document Document
|
||||
static CIDSystemInfo readCIDSystemInfo(const PDFObject& cidSystemInfoObject, const PDFDocument* document);
|
||||
|
||||
/// Returns font id from the font dictionary
|
||||
QByteArray getFontId() const;
|
||||
|
||||
protected:
|
||||
CIDSystemInfo m_CIDSystemInfo;
|
||||
FontDescriptor m_fontDescriptor;
|
||||
QByteArray m_fontId;
|
||||
};
|
||||
|
||||
/// Simple font, see PDF reference 1.7, chapter 5.5. Simple fonts have encoding table,
|
||||
@ -344,6 +349,7 @@ class PDFSimpleFont : public PDFFont
|
||||
|
||||
public:
|
||||
explicit PDFSimpleFont(CIDSystemInfo cidSystemInfo,
|
||||
QByteArray fontId,
|
||||
FontDescriptor fontDescriptor,
|
||||
QByteArray name,
|
||||
QByteArray baseFont,
|
||||
@ -381,6 +387,7 @@ class PDFType1Font : public PDFSimpleFont
|
||||
|
||||
public:
|
||||
explicit PDFType1Font(FontType fontType,
|
||||
QByteArray fontId,
|
||||
CIDSystemInfo cidSystemInfo,
|
||||
FontDescriptor fontDescriptor,
|
||||
QByteArray name,
|
||||
@ -434,7 +441,8 @@ public:
|
||||
/// Retrieves font from the cache. If font can't be accessed or created,
|
||||
/// then exception is thrown.
|
||||
/// \param fontObject Font object
|
||||
PDFFontPointer getFont(const PDFObject& fontObject) const;
|
||||
/// \param fontId Font identification in resource dictionary
|
||||
PDFFontPointer getFont(const PDFObject& fontObject, const QByteArray& fontId) const;
|
||||
|
||||
/// Retrieves realized font from the cache. If realized font can't be accessed or created,
|
||||
/// then exception is thrown.
|
||||
@ -600,6 +608,7 @@ class PDFType3Font : public PDFFont
|
||||
{
|
||||
public:
|
||||
explicit PDFType3Font(FontDescriptor fontDescriptor,
|
||||
QByteArray fontId,
|
||||
int firstCharacterIndex,
|
||||
int lastCharacterIndex,
|
||||
QTransform fontMatrix,
|
||||
@ -641,8 +650,15 @@ private:
|
||||
class PDFType0Font : public PDFFont
|
||||
{
|
||||
public:
|
||||
explicit inline PDFType0Font(CIDSystemInfo cidSystemInfo, FontDescriptor fontDescriptor, PDFFontCMap cmap, PDFFontCMap toUnicode, PDFCIDtoGIDMapper mapper, PDFReal defaultAdvance, std::unordered_map<CID, PDFReal> advances) :
|
||||
PDFFont(qMove(cidSystemInfo), qMove(fontDescriptor)),
|
||||
explicit inline PDFType0Font(CIDSystemInfo cidSystemInfo,
|
||||
QByteArray fontId,
|
||||
FontDescriptor fontDescriptor,
|
||||
PDFFontCMap cmap,
|
||||
PDFFontCMap toUnicode,
|
||||
PDFCIDtoGIDMapper mapper,
|
||||
PDFReal defaultAdvance,
|
||||
std::unordered_map<CID, PDFReal> advances) :
|
||||
PDFFont(qMove(cidSystemInfo), qMove(fontId), qMove(fontDescriptor)),
|
||||
m_cmap(qMove(cmap)),
|
||||
m_toUnicode(qMove(toUnicode)),
|
||||
m_mapper(qMove(mapper)),
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include "pdfpagecontenteditorprocessor.h"
|
||||
|
||||
#include <QStringBuilder>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
||||
@ -629,4 +631,108 @@ void PDFEditedPageContentElementText::setTextPath(QPainterPath newTextPath)
|
||||
m_textPath = newTextPath;
|
||||
}
|
||||
|
||||
QString PDFEditedPageContentElementText::getItemsAsText() const
|
||||
{
|
||||
QString text;
|
||||
|
||||
PDFPageContentProcessorState state = getState();
|
||||
state.setStateFlags(PDFPageContentProcessorState::StateFlags());
|
||||
|
||||
for (const Item& item : getItems())
|
||||
{
|
||||
if (item.isText)
|
||||
{
|
||||
for (const TextSequenceItem& textItem : item.textSequence.items)
|
||||
{
|
||||
if (textItem.isCharacter())
|
||||
{
|
||||
if (!textItem.character.isNull())
|
||||
{
|
||||
text += QString(textItem.character).toHtmlEscaped();
|
||||
}
|
||||
else if (textItem.isAdvance())
|
||||
{
|
||||
text += QString("<space advance=\"%1\"/>").arg(textItem.advance);
|
||||
}
|
||||
else if (textItem.cid != 0)
|
||||
{
|
||||
text += QString("<character cid=\"%1\"/>").arg(textItem.cid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.isUpdateGraphicState)
|
||||
{
|
||||
PDFPageContentProcessorState newState = state;
|
||||
newState.setStateFlags(PDFPageContentProcessorState::StateFlags());
|
||||
|
||||
newState.setState(item.state);
|
||||
PDFPageContentProcessorState::StateFlags flags = newState.getStateFlags();
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextRenderingMode))
|
||||
{
|
||||
text += QString("<tr v=\"%1\"/>").arg(int(newState.getTextRenderingMode()));
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextRise))
|
||||
{
|
||||
text += QString("<ts v=\"%1\"/>").arg(newState.getTextRise());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextCharacterSpacing))
|
||||
{
|
||||
text += QString("<tc v=\"%1\"/>").arg(newState.getTextCharacterSpacing());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextWordSpacing))
|
||||
{
|
||||
text += QString("<tw v=\"%1\"/>").arg(newState.getTextWordSpacing());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextLeading))
|
||||
{
|
||||
text += QString("<tl v=\"%1\"/>").arg(newState.getTextLeading());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextHorizontalScaling))
|
||||
{
|
||||
text += QString("<tz v=\"%1\"/>").arg(newState.getTextHorizontalScaling());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextKnockout))
|
||||
{
|
||||
text += QString("<tk v=\"%1\"/>").arg(newState.getTextKnockout());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextFont) ||
|
||||
flags.testFlag(PDFPageContentProcessorState::StateTextFontSize))
|
||||
{
|
||||
text += QString("<tf font=\"%1\" size=\"%2\"/>").arg(newState.getTextFont()->getFontId()).arg(newState.getTextFontSize());
|
||||
}
|
||||
|
||||
if (flags.testFlag(PDFPageContentProcessorState::StateTextMatrix))
|
||||
{
|
||||
QTransform transform = newState.getTextMatrix();
|
||||
|
||||
qreal x = transform.dx();
|
||||
qreal y = transform.dy();
|
||||
|
||||
if (transform.isTranslating())
|
||||
{
|
||||
text += QString("<tpos x=\"%1\" y=\"%2\"/>").arg(x).arg(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
text += QString("<tmatrix m11=\"%1\" m12=\"%2\" m21=\"%3\" m22=\"%4\" x=\"%5\" y=\"%6\"/>").arg(transform.m11()).arg(transform.m12()).arg(transform.m21()).arg(transform.m22()).arg(x).arg(y);
|
||||
}
|
||||
}
|
||||
|
||||
state = newState;
|
||||
state.setStateFlags(PDFPageContentProcessorState::StateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -152,6 +152,8 @@ public:
|
||||
QPainterPath getTextPath() const;
|
||||
void setTextPath(QPainterPath newTextPath);
|
||||
|
||||
QString getItemsAsText() const;
|
||||
|
||||
private:
|
||||
std::vector<Item> m_items;
|
||||
QRectF m_boundingBox;
|
||||
|
@ -2749,7 +2749,7 @@ void PDFPageContentProcessor::operatorTextSetFontAndFontSize(PDFOperandName font
|
||||
{
|
||||
try
|
||||
{
|
||||
PDFFontPointer font = m_fontCache->getFont(m_fontDictionary->get(fontName.name));
|
||||
PDFFontPointer font = m_fontCache->getFont(m_fontDictionary->get(fontName.name), fontName.name);
|
||||
|
||||
m_graphicState.setTextFont(qMove(font));
|
||||
m_graphicState.setTextFontSize(fontSize);
|
||||
@ -3504,47 +3504,52 @@ PDFPageContentProcessorState::~PDFPageContentProcessorState()
|
||||
|
||||
PDFPageContentProcessorState& PDFPageContentProcessorState::operator=(const PDFPageContentProcessorState& other)
|
||||
{
|
||||
setCurrentTransformationMatrix(other.getCurrentTransformationMatrix());
|
||||
setStrokeColorSpace(other.m_strokeColorSpace);
|
||||
setFillColorSpace(other.m_fillColorSpace);
|
||||
setStrokeColor(other.getStrokeColor(), other.getStrokeColorOriginal());
|
||||
setFillColor(other.getFillColor(), other.getFillColorOriginal());
|
||||
setLineWidth(other.getLineWidth());
|
||||
setLineCapStyle(other.getLineCapStyle());
|
||||
setLineJoinStyle(other.getLineJoinStyle());
|
||||
setMitterLimit(other.getMitterLimit());
|
||||
setLineDashPattern(other.getLineDashPattern());
|
||||
setRenderingIntentName(other.getRenderingIntentName());
|
||||
setFlatness(other.getFlatness());
|
||||
setSmoothness(other.getSmoothness());
|
||||
setTextCharacterSpacing(other.getTextCharacterSpacing());
|
||||
setTextWordSpacing(other.getTextWordSpacing());
|
||||
setTextHorizontalScaling(other.getTextHorizontalScaling());
|
||||
setTextLeading(other.getTextLeading());
|
||||
setTextFont(other.getTextFont());
|
||||
setTextFontSize(other.getTextFontSize());
|
||||
setTextRenderingMode(other.getTextRenderingMode());
|
||||
setTextRise(other.getTextRise());
|
||||
setTextKnockout(other.getTextKnockout());
|
||||
setTextMatrix(other.getTextMatrix());
|
||||
setTextLineMatrix(other.getTextLineMatrix());
|
||||
setAlphaStroking(other.getAlphaStroking());
|
||||
setAlphaFilling(other.getAlphaFilling());
|
||||
setBlendMode(other.getBlendMode());
|
||||
setRenderingIntent(other.getRenderingIntent());
|
||||
setOverprintMode(other.getOverprintMode());
|
||||
setAlphaIsShape(other.getAlphaIsShape());
|
||||
setStrokeAdjustment(other.getStrokeAdjustment());
|
||||
setSoftMask(other.getSoftMask());
|
||||
setBlackPointCompensationMode(other.getBlackPointCompensationMode());
|
||||
setBlackGenerationFunction(other.getBlackGenerationFunction());
|
||||
setUndercolorRemovalFunction(other.getUndercolorRemovalFunction());
|
||||
setTransferFunction(other.getTransferFunction());
|
||||
setHalftone(other.getHalftone());
|
||||
setHalftoneOrigin(other.getHalftoneOrigin());
|
||||
setState(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PDFPageContentProcessorState::setState(const PDFPageContentProcessorState& state)
|
||||
{
|
||||
setCurrentTransformationMatrix(state.getCurrentTransformationMatrix());
|
||||
setStrokeColorSpace(state.m_strokeColorSpace);
|
||||
setFillColorSpace(state.m_fillColorSpace);
|
||||
setStrokeColor(state.getStrokeColor(), state.getStrokeColorOriginal());
|
||||
setFillColor(state.getFillColor(), state.getFillColorOriginal());
|
||||
setLineWidth(state.getLineWidth());
|
||||
setLineCapStyle(state.getLineCapStyle());
|
||||
setLineJoinStyle(state.getLineJoinStyle());
|
||||
setMitterLimit(state.getMitterLimit());
|
||||
setLineDashPattern(state.getLineDashPattern());
|
||||
setRenderingIntentName(state.getRenderingIntentName());
|
||||
setFlatness(state.getFlatness());
|
||||
setSmoothness(state.getSmoothness());
|
||||
setTextCharacterSpacing(state.getTextCharacterSpacing());
|
||||
setTextWordSpacing(state.getTextWordSpacing());
|
||||
setTextHorizontalScaling(state.getTextHorizontalScaling());
|
||||
setTextLeading(state.getTextLeading());
|
||||
setTextFont(state.getTextFont());
|
||||
setTextFontSize(state.getTextFontSize());
|
||||
setTextRenderingMode(state.getTextRenderingMode());
|
||||
setTextRise(state.getTextRise());
|
||||
setTextKnockout(state.getTextKnockout());
|
||||
setTextMatrix(state.getTextMatrix());
|
||||
setTextLineMatrix(state.getTextLineMatrix());
|
||||
setAlphaStroking(state.getAlphaStroking());
|
||||
setAlphaFilling(state.getAlphaFilling());
|
||||
setBlendMode(state.getBlendMode());
|
||||
setRenderingIntent(state.getRenderingIntent());
|
||||
setOverprintMode(state.getOverprintMode());
|
||||
setAlphaIsShape(state.getAlphaIsShape());
|
||||
setStrokeAdjustment(state.getStrokeAdjustment());
|
||||
setSoftMask(state.getSoftMask());
|
||||
setBlackPointCompensationMode(state.getBlackPointCompensationMode());
|
||||
setBlackGenerationFunction(state.getBlackGenerationFunction());
|
||||
setUndercolorRemovalFunction(state.getUndercolorRemovalFunction());
|
||||
setTransferFunction(state.getTransferFunction());
|
||||
setHalftone(state.getHalftone());
|
||||
setHalftoneOrigin(state.getHalftoneOrigin());
|
||||
}
|
||||
|
||||
void PDFPageContentProcessorState::setCurrentTransformationMatrix(const QTransform& currentTransformationMatrix)
|
||||
{
|
||||
if (m_currentTransformationMatrix != currentTransformationMatrix)
|
||||
|
@ -156,6 +156,8 @@ public:
|
||||
|
||||
using StateFlags = PDFFlags<StateFlag>;
|
||||
|
||||
void setState(const PDFPageContentProcessorState& state);
|
||||
|
||||
const QTransform& getCurrentTransformationMatrix() const { return m_currentTransformationMatrix; }
|
||||
void setCurrentTransformationMatrix(const QTransform& currentTransformationMatrix);
|
||||
|
||||
|
@ -117,4 +117,59 @@ QBrush PDFPainterHelper::createBrushFromState(const PDFPageContentProcessorState
|
||||
}
|
||||
}
|
||||
|
||||
PDFTransformationDecomposition PDFPainterHelper::decomposeTransform(const QTransform& transform)
|
||||
{
|
||||
PDFTransformationDecomposition result;
|
||||
|
||||
const qreal m11 = transform.m11();
|
||||
const qreal m12 = transform.m12();
|
||||
const qreal m21 = transform.m21();
|
||||
const qreal m22 = transform.m22();
|
||||
|
||||
const qreal dx = transform.dx();
|
||||
const qreal dy = transform.dy();
|
||||
|
||||
const qreal sx = std::sqrt(m11 * m11 + m21 * m21);
|
||||
const qreal phi = std::atan2(m21, m11);
|
||||
const qreal msy = m12 * std::cos(phi) + m22 * std::sin(phi);
|
||||
const qreal sy = -m12 * std::sin(phi) + m22 * std::cos(phi);
|
||||
|
||||
result.rotationAngle = phi;
|
||||
result.scaleX = sx;
|
||||
result.scaleY = sy;
|
||||
|
||||
if (!qFuzzyIsNull(sy))
|
||||
{
|
||||
result.shearFactor = msy / sy;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.shearFactor = 0.0;
|
||||
}
|
||||
|
||||
result.translateX = dx;
|
||||
result.translateY = dy;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QTransform PDFPainterHelper::composeTransform(const PDFTransformationDecomposition& decomposition)
|
||||
{
|
||||
const qreal s = std::sin(decomposition.rotationAngle);
|
||||
const qreal c = std::cos(decomposition.rotationAngle);
|
||||
|
||||
const qreal m = decomposition.shearFactor;
|
||||
const qreal sx = decomposition.scaleX;
|
||||
const qreal sy = decomposition.scaleY;
|
||||
const qreal dx = decomposition.translateX;
|
||||
const qreal dy = decomposition.translateY;
|
||||
|
||||
const qreal m11 = sx * c;
|
||||
const qreal m12 = sy * m * c - sy * s;
|
||||
const qreal m21 = sx * s;
|
||||
const qreal m22 = sy * m * s + sy * c;
|
||||
|
||||
return QTransform(m11, m12, m21, m22, dx, dy);
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -45,6 +45,16 @@ private:
|
||||
QPainter* m_painter;
|
||||
};
|
||||
|
||||
struct PDFTransformationDecomposition
|
||||
{
|
||||
double rotationAngle = 0.0;
|
||||
double shearFactor = 0.0;
|
||||
double scaleX = 0.0;
|
||||
double scaleY = 0.0;
|
||||
double translateX = 0.0;
|
||||
double translateY = 0.0;
|
||||
};
|
||||
|
||||
class PDF4QTLIBCORESHARED_EXPORT PDFPainterHelper
|
||||
{
|
||||
public:
|
||||
@ -62,6 +72,12 @@ public:
|
||||
|
||||
/// Creates brush from painter graphicState
|
||||
static QBrush createBrushFromState(const PDFPageContentProcessorState* graphicState, double alpha);
|
||||
|
||||
/// Decompose transform
|
||||
static PDFTransformationDecomposition decomposeTransform(const QTransform& transform);
|
||||
|
||||
/// Compose transform
|
||||
static QTransform composeTransform(const PDFTransformationDecomposition& decomposition);
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -331,7 +331,7 @@ void PDFDocumentPropertiesDialog::initializeFonts(const pdf::PDFDocument* docume
|
||||
|
||||
try
|
||||
{
|
||||
if (pdf::PDFFontPointer font = pdf::PDFFont::createFont(object, document))
|
||||
if (pdf::PDFFontPointer font = pdf::PDFFont::createFont(object, fontsDictionary->getKey(i).getString(), document))
|
||||
{
|
||||
pdf::PDFRenderErrorReporterDummy dummyReporter;
|
||||
pdf::PDFRealizedFontPointer realizedFont = pdf::PDFRealizedFont::createRealizedFont(font, 8.0, &dummyReporter);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "pdfpagecontentelements.h"
|
||||
#include "pdfpagecontenteditorprocessor.h"
|
||||
#include "pdfwidgetutils.h"
|
||||
#include "pdfpainterutils.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
@ -58,6 +59,25 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
|
||||
m_image = imageElement->getImage();
|
||||
setImage(imageElement->getImage());
|
||||
}
|
||||
|
||||
if (PDFEditedPageContentElementText* textElement = editedElement->getElement()->asText())
|
||||
{
|
||||
ui->tabWidget->addTab(ui->textTab, tr("Text"));
|
||||
QString text = textElement->getItemsAsText();
|
||||
ui->plainTextEdit->setPlainText(text);
|
||||
}
|
||||
|
||||
QTransform matrix = editedElement->getElement()->getState().getCurrentTransformationMatrix();
|
||||
PDFTransformationDecomposition decomposedTransformation = PDFPainterHelper::decomposeTransform(matrix);
|
||||
|
||||
ui->rotationAngleEdit->setValue(qRadiansToDegrees(decomposedTransformation.rotationAngle));
|
||||
ui->scaleInXEdit->setValue(decomposedTransformation.scaleX);
|
||||
ui->scaleInYEdit->setValue(decomposedTransformation.scaleY);
|
||||
ui->shearFactorEdit->setValue(decomposedTransformation.shearFactor);
|
||||
ui->translateInXEdit->setValue(decomposedTransformation.translateX);
|
||||
ui->translateInYEdit->setValue(decomposedTransformation.translateY);
|
||||
|
||||
ui->tabWidget->addTab(ui->transformationTab, tr("Transformation"));
|
||||
}
|
||||
|
||||
void PDFPageContentEditorEditedItemSettings::saveToElement(PDFPageContentElementEdited* editedElement)
|
||||
|
@ -17,7 +17,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="textTab">
|
||||
<attribute name="title">
|
||||
@ -143,6 +143,169 @@
|
||||
<attribute name="title">
|
||||
<string>Transformation</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="transformationTabWidgetsLayout" columnstretch="1,0,1">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="translationInYLabel">
|
||||
<property name="text">
|
||||
<string>Translation in Y</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QDoubleSpinBox" name="translateInYEdit">
|
||||
<property name="minimum">
|
||||
<double>-1000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="translationInXLabel">
|
||||
<property name="text">
|
||||
<string>Translation in X</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QDoubleSpinBox" name="scaleInXEdit">
|
||||
<property name="minimum">
|
||||
<double>-1000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="scaleInXLabel">
|
||||
<property name="text">
|
||||
<string>Scale in X</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QDoubleSpinBox" name="rotationAngleEdit">
|
||||
<property name="minimum">
|
||||
<double>-360.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>360.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QDoubleSpinBox" name="translateInXEdit">
|
||||
<property name="minimum">
|
||||
<double>-1000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QDoubleSpinBox" name="shearFactorEdit">
|
||||
<property name="minimum">
|
||||
<double>-1000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="scaleInYLabel">
|
||||
<property name="text">
|
||||
<string>Scale in Y</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="shearFactorLabel">
|
||||
<property name="text">
|
||||
<string>Shear factor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="rotationAngleLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Rotation angle</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QDoubleSpinBox" name="scaleInYEdit">
|
||||
<property name="minimum">
|
||||
<double>-1000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="rotationAngleSymbolLabel">
|
||||
<property name="text">
|
||||
<string>φ</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="scaleInXSymbolLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>s<span style=" vertical-align:sub;">x</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="scaleInYSymbolLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>s<span style=" vertical-align:sub;">y</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="shearFactorSymbolLabel">
|
||||
<property name="text">
|
||||
<string>m</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="translationInXSymbolLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>t<span style=" vertical-align:sub;">x</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="translationInYSymbolLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>t<span style=" vertical-align:sub;">y</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -120,7 +120,7 @@ int PDFToolInfoFonts::execute(const PDFToolOptions& options)
|
||||
|
||||
try
|
||||
{
|
||||
if (pdf::PDFFontPointer font = pdf::PDFFont::createFont(object, &document))
|
||||
if (pdf::PDFFontPointer font = pdf::PDFFont::createFont(object, fontsDictionary->getKey(i).getString(), &document))
|
||||
{
|
||||
pdf::PDFRenderErrorReporterDummy dummyReporter;
|
||||
pdf::PDFRealizedFontPointer realizedFont = pdf::PDFRealizedFont::createRealizedFont(font, 8.0, &dummyReporter);
|
||||
|
Loading…
x
Reference in New Issue
Block a user