mirror of https://github.com/JakubMelka/PDF4QT.git
Issue #107: Bugfixing
This commit is contained in:
parent
805c967b70
commit
47f0bffeca
|
@ -1026,7 +1026,7 @@ void PDFPageContentStreamBuilder::replaceResources(PDFObjectReference contentStr
|
||||||
QByteArray compressedData = PDFFlateDecodeFilter::compress(decodedStream);
|
QByteArray compressedData = PDFFlateDecodeFilter::compress(decodedStream);
|
||||||
PDFDictionary updatedDictionary = *contentStreamObject.getStream()->getDictionary();
|
PDFDictionary updatedDictionary = *contentStreamObject.getStream()->getDictionary();
|
||||||
updatedDictionary.setEntry(PDFInplaceOrMemoryString("Length"), PDFObject::createInteger(compressedData.size()));
|
updatedDictionary.setEntry(PDFInplaceOrMemoryString("Length"), PDFObject::createInteger(compressedData.size()));
|
||||||
updatedDictionary.setEntry(PDFInplaceOrMemoryString("Filters"), PDFObject::createArray(std::make_shared<PDFArray>(qMove(array))));
|
updatedDictionary.setEntry(PDFInplaceOrMemoryString("Filter"), PDFObject::createArray(std::make_shared<PDFArray>(qMove(array))));
|
||||||
PDFObject newContentStream = PDFObject::createStream(std::make_shared<PDFStream>(qMove(updatedDictionary), qMove(compressedData)));
|
PDFObject newContentStream = PDFObject::createStream(std::make_shared<PDFStream>(qMove(updatedDictionary), qMove(compressedData)));
|
||||||
m_documentBuilder->setObject(contentStreamReference, std::move(newContentStream));
|
m_documentBuilder->setObject(contentStreamReference, std::move(newContentStream));
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Bit writer
|
/// Bit writer
|
||||||
class PDFBitWriter
|
class PDF4QTLIBSHARED_EXPORT PDFBitWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Value = uint64_t;
|
using Value = uint64_t;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "pdfwidgetutils.h"
|
#include "pdfwidgetutils.h"
|
||||||
#include "pdfimageconversion.h"
|
#include "pdfimageconversion.h"
|
||||||
#include "pdfstreamfilters.h"
|
#include "pdfstreamfilters.h"
|
||||||
|
#include "pdfutils.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -240,6 +241,8 @@ PDFCreateBitonalDocumentDialog::PDFCreateBitonalDocumentDialog(const pdf::PDFDoc
|
||||||
|
|
||||||
ui->imageListWidget->setItemDelegate( new ImagePreviewDelegate(&m_imagesToBeConverted, this));
|
ui->imageListWidget->setItemDelegate( new ImagePreviewDelegate(&m_imagesToBeConverted, this));
|
||||||
|
|
||||||
|
setGeometry(parent->geometry());
|
||||||
|
|
||||||
loadImages();
|
loadImages();
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
@ -312,7 +315,22 @@ void PDFCreateBitonalDocumentDialog::createBitonalDocument()
|
||||||
QImage bitonicImage = imageConversion.getConvertedImage();
|
QImage bitonicImage = imageConversion.getConvertedImage();
|
||||||
Q_ASSERT(bitonicImage.format() == QImage::Format_Mono);
|
Q_ASSERT(bitonicImage.format() == QImage::Format_Mono);
|
||||||
|
|
||||||
QByteArray imageData((const char*)bitonicImage.constBits(), bitonicImage.sizeInBytes());
|
pdf::PDFBitWriter bitWriter(1);
|
||||||
|
bitWriter.reserve(bitonicImage.sizeInBytes());
|
||||||
|
for (int row = 0; row < bitonicImage.height(); ++row)
|
||||||
|
{
|
||||||
|
for (int col = 0; col < bitonicImage.width(); ++col)
|
||||||
|
{
|
||||||
|
QRgb pixelValue = bitonicImage.pixel(col, row);
|
||||||
|
QRgb withoutAlphaValue = pixelValue & 0xFFFFFF;
|
||||||
|
int value = withoutAlphaValue > 0 ? 1 : 0;
|
||||||
|
bitWriter.write(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bitWriter.finishLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray imageData = bitWriter.takeByteArray();
|
||||||
QByteArray compressedData = pdf::PDFFlateDecodeFilter::compress(imageData);
|
QByteArray compressedData = pdf::PDFFlateDecodeFilter::compress(imageData);
|
||||||
|
|
||||||
pdf::PDFArray array;
|
pdf::PDFArray array;
|
||||||
|
@ -327,7 +345,7 @@ void PDFCreateBitonalDocumentDialog::createBitonalDocument()
|
||||||
dictionary.addEntry(pdf::PDFInplaceOrMemoryString("BitsPerComponent"), pdf::PDFObject::createInteger(1));
|
dictionary.addEntry(pdf::PDFInplaceOrMemoryString("BitsPerComponent"), pdf::PDFObject::createInteger(1));
|
||||||
dictionary.addEntry(pdf::PDFInplaceOrMemoryString("Predictor"), pdf::PDFObject::createInteger(1));
|
dictionary.addEntry(pdf::PDFInplaceOrMemoryString("Predictor"), pdf::PDFObject::createInteger(1));
|
||||||
dictionary.setEntry(pdf::PDFInplaceOrMemoryString("Length"), pdf::PDFObject::createInteger(compressedData.size()));
|
dictionary.setEntry(pdf::PDFInplaceOrMemoryString("Length"), pdf::PDFObject::createInteger(compressedData.size()));
|
||||||
dictionary.setEntry(pdf::PDFInplaceOrMemoryString("Filters"), pdf::PDFObject::createArray(std::make_shared<pdf::PDFArray>(qMove(array))));
|
dictionary.setEntry(pdf::PDFInplaceOrMemoryString("Filter"), pdf::PDFObject::createArray(std::make_shared<pdf::PDFArray>(qMove(array))));
|
||||||
|
|
||||||
pdf::PDFObject imageObject = pdf::PDFObject::createStream(std::make_shared<pdf::PDFStream>(qMove(dictionary), qMove(compressedData)));
|
pdf::PDFObject imageObject = pdf::PDFObject::createStream(std::make_shared<pdf::PDFStream>(qMove(dictionary), qMove(compressedData)));
|
||||||
storage.setObject(reference, std::move(imageObject));
|
storage.setObject(reference, std::move(imageObject));
|
||||||
|
@ -363,14 +381,8 @@ void PDFCreateBitonalDocumentDialog::loadImages()
|
||||||
ui->imageListWidget->setIconSize(iconSize);
|
ui->imageListWidget->setIconSize(iconSize);
|
||||||
QSize imageSize = iconSize * ui->imageListWidget->devicePixelRatioF();
|
QSize imageSize = iconSize * ui->imageListWidget->devicePixelRatioF();
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (pdf::PDFObjectReference reference : m_imageReferences)
|
for (pdf::PDFObjectReference reference : m_imageReferences)
|
||||||
{
|
{
|
||||||
if (i++>1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<pdf::PDFImage> pdfImage = getImageFromReference(reference);
|
std::optional<pdf::PDFImage> pdfImage = getImageFromReference(reference);
|
||||||
if (!pdfImage)
|
if (!pdfImage)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue