mirror of https://github.com/JakubMelka/PDF4QT.git
Minor bugfixes
This commit is contained in:
parent
9a17daa5ab
commit
ed15e37a52
|
@ -516,11 +516,12 @@ PDFImage PDFImage::createImage(const PDFDocument* document, const PDFStream* str
|
|||
|
||||
QImage PDFImage::getImage() const
|
||||
{
|
||||
if (m_colorSpace)
|
||||
const bool isImageMask = m_imageData.getMaskingType() == PDFImageData::MaskingType::ImageMask;
|
||||
if (m_colorSpace && !isImageMask)
|
||||
{
|
||||
return m_colorSpace->getImage(m_imageData);
|
||||
}
|
||||
else if (m_imageData.getMaskingType() == PDFImageData::MaskingType::ImageMask)
|
||||
else if (isImageMask)
|
||||
{
|
||||
if (m_imageData.getBitsPerComponent() != 1)
|
||||
{
|
||||
|
@ -533,7 +534,6 @@ QImage PDFImage::getImage() const
|
|||
}
|
||||
|
||||
QImage image(m_imageData.getWidth(), m_imageData.getHeight(), QImage::Format_Alpha8);
|
||||
image.fill(QColor(Qt::transparent));
|
||||
|
||||
const bool flip01 = !m_imageData.getDecode().empty() && qFuzzyCompare(m_imageData.getDecode().front(), 1.0);
|
||||
QDataStream stream(const_cast<QByteArray*>(&m_imageData.getData()), QIODevice::ReadOnly);
|
||||
|
|
|
@ -2037,6 +2037,15 @@ void PDFPageContentProcessor::paintXObjectImage(const PDFStream* stream)
|
|||
PDFImage pdfImage = PDFImage::createImage(m_document, stream, qMove(colorSpace), this);
|
||||
QImage image = pdfImage.getImage();
|
||||
|
||||
if (image.format() == QImage::Format_Alpha8)
|
||||
{
|
||||
QSize size = image.size();
|
||||
QImage unmaskedImage(size, QImage::Format_ARGB32_Premultiplied);
|
||||
unmaskedImage.fill(m_graphicState.getFillColor());
|
||||
unmaskedImage.setAlphaChannel(image);
|
||||
image = qMove(unmaskedImage);
|
||||
}
|
||||
|
||||
if (!image.isNull())
|
||||
{
|
||||
performImagePainting(image);
|
||||
|
@ -2287,19 +2296,25 @@ void PDFPageContentProcessor::drawText(const TextSequence& textSequence)
|
|||
{
|
||||
// Type 3 Font
|
||||
|
||||
PDFPageContentProcessorStateGuard guard(this);
|
||||
|
||||
Q_ASSERT(dynamic_cast<const PDFType3Font*>(m_graphicState.getTextFont().get()));
|
||||
const PDFType3Font* parentFont = static_cast<const PDFType3Font*>(m_graphicState.getTextFont().get());
|
||||
|
||||
QMatrix fontMatrix = parentFont->getFontMatrix();
|
||||
if (!fontMatrix.isInvertible())
|
||||
{
|
||||
throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Type 3 font matrix is not invertible."));
|
||||
}
|
||||
|
||||
PDFPageContentProcessorStateGuard guard(this);
|
||||
|
||||
QMatrix invertedFontMatrix = fontMatrix.inverted();
|
||||
PDFObject resources = parentFont->getResources();
|
||||
if (!resources.isNull())
|
||||
{
|
||||
initDictionaries(resources);
|
||||
}
|
||||
|
||||
QMatrix fontAdjustedMatrix = fontMatrix * adjustMatrix;
|
||||
QMatrix fontAdjustedMatrix = invertedFontMatrix * adjustMatrix;
|
||||
|
||||
for (const TextSequenceItem& item : textSequence.items)
|
||||
{
|
||||
|
|
|
@ -50,10 +50,48 @@ QList<PDFRenderError> PDFRenderer::render(QPainter* painter, const QRectF& recta
|
|||
Q_ASSERT(page);
|
||||
|
||||
QRectF mediaBox = page->getMediaBox();
|
||||
const PageRotation rotation = page->getPageRotation();
|
||||
mediaBox = page->getRotatedBox(mediaBox, rotation);
|
||||
|
||||
QMatrix matrix;
|
||||
matrix.translate(rectangle.left(), rectangle.bottom());
|
||||
matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height());
|
||||
switch (rotation)
|
||||
{
|
||||
case PageRotation::None:
|
||||
{
|
||||
matrix.translate(rectangle.left(), rectangle.bottom());
|
||||
matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height());
|
||||
break;
|
||||
}
|
||||
|
||||
case PageRotation::Rotate90:
|
||||
{
|
||||
matrix.translate(rectangle.left(), rectangle.top());
|
||||
matrix.rotate(90);
|
||||
matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height());
|
||||
break;
|
||||
}
|
||||
|
||||
case PageRotation::Rotate270:
|
||||
{
|
||||
matrix.translate(rectangle.right(), rectangle.top());
|
||||
matrix.rotate(-90);
|
||||
matrix.scale(rectangle.width() / mediaBox.width(), -rectangle.height() / mediaBox.height());
|
||||
break;
|
||||
}
|
||||
|
||||
case PageRotation::Rotate180:
|
||||
{
|
||||
matrix.translate(rectangle.left(), rectangle.top());
|
||||
matrix.scale(rectangle.width() / mediaBox.width(), rectangle.height() / mediaBox.height());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PDFPainter processor(painter, m_features, matrix, page, m_document, m_fontCache, m_optionalContentActivity);
|
||||
return processor.processContents();
|
||||
|
|
Loading…
Reference in New Issue