Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion reader/browser/BrowserPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,11 @@ BrowserWord *BrowserPage::getBrowserWord(const QPointF &point)
bool BrowserPage::isBigDoc()
{
qCDebug(appLog) << "BrowserPage::isBigDoc() - Starting is big doc";
bool isBig = Dr::PDF == m_sheet->fileType() && boundingRect().width() > 1000 && boundingRect().height() > 1000;
bool supportedType = (Dr::PDF == m_sheet->fileType());
#ifdef XPS_SUPPORT_ENABLED
supportedType = supportedType || (Dr::XPS == m_sheet->fileType());
#endif
bool isBig = supportedType && boundingRect().width() > 1000 && boundingRect().height() > 1000;
qCDebug(appLog) << "Checking if document is big:" << isBig;
return isBig;
}
23 changes: 13 additions & 10 deletions reader/browser/SheetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,22 +893,25 @@ void SheetBrowser::deform(SheetOperation &operation)

m_lastScaleFactor = operation.scaleFactor;

const qreal safeMaxWidth = qFuzzyIsNull(m_maxWidth) ? 1.0 : m_maxWidth;
const qreal safeMaxHeight = qFuzzyIsNull(m_maxHeight) ? (qFuzzyIsNull(m_maxWidth) ? 1.0 : m_maxWidth) : m_maxHeight;

//根据缩放模式调整缩放比例
switch (operation.rotation) {
default:
case Dr::RotateBy0:
case Dr::RotateBy180:
qCDebug(appLog) << "SheetBrowser::deform() - Rotation is 0 or 180";
if (Dr::FitToPageWidthMode == operation.scaleMode)
operation.scaleFactor = static_cast<double>(this->width() - 25.0) / m_maxWidth / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
operation.scaleFactor = static_cast<double>(this->width() - 25.0) / safeMaxWidth / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
else if (Dr::FitToPageHeightMode == operation.scaleMode)
operation.scaleFactor = static_cast<double>(this->height()) / m_maxHeight;
operation.scaleFactor = static_cast<double>(this->height()) / safeMaxHeight;
else if (Dr::FitToPageDefaultMode == operation.scaleMode)
operation.scaleFactor = 1.0 ;
else if (Dr::FitToPageWorHMode == operation.scaleMode) {
qreal scaleFactor = static_cast<double>(this->width() - 25.0) / m_maxWidth / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
if (scaleFactor * m_maxHeight > this->height())
scaleFactor = static_cast<double>(this->height()) / m_maxHeight;
qreal scaleFactor = static_cast<double>(this->width() - 25.0) / safeMaxWidth / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
if (scaleFactor * safeMaxHeight > this->height())
scaleFactor = static_cast<double>(this->height()) / safeMaxHeight;
operation.scaleFactor = scaleFactor;
} else
operation.scaleMode = Dr::ScaleFactorMode;
Expand All @@ -917,15 +920,15 @@ void SheetBrowser::deform(SheetOperation &operation)
case Dr::RotateBy270:
qCDebug(appLog) << "SheetBrowser::deform() - Rotation is 90 or 270";
if (Dr::FitToPageWidthMode == operation.scaleMode)
operation.scaleFactor = static_cast<double>(this->width() - 25.0) / m_maxHeight / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
operation.scaleFactor = static_cast<double>(this->width() - 25.0) / safeMaxHeight / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
else if (Dr::FitToPageHeightMode == operation.scaleMode)
operation.scaleFactor = static_cast<double>(this->height()) / m_maxWidth;
operation.scaleFactor = static_cast<double>(this->height()) / safeMaxWidth;
else if (Dr::FitToPageDefaultMode == operation.scaleMode)
operation.scaleFactor = 1.0 ;
else if (Dr::FitToPageWorHMode == operation.scaleMode) {
qreal scaleFactor = static_cast<double>(this->width() - 25.0) / m_maxHeight / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
if (scaleFactor * m_maxWidth > this->height())
scaleFactor = static_cast<double>(this->height()) / m_maxWidth;
qreal scaleFactor = static_cast<double>(this->width() - 25.0) / safeMaxHeight / (Dr::TwoPagesMode == operation.layoutMode ? 2 : 1);
if (scaleFactor * safeMaxWidth > this->height())
scaleFactor = static_cast<double>(this->height()) / safeMaxWidth;
operation.scaleFactor = scaleFactor;
} else
operation.scaleMode = Dr::ScaleFactorMode;
Expand Down
48 changes: 31 additions & 17 deletions reader/document/XpsDocumentAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,30 @@ QImage XpsDocumentAdapter::renderPage(int pageIndex, int width, int height, cons
}

const QSizeF logicalSize = m_pageSizes.at(pageIndex);
const QRectF fullRect(QPointF(0, 0), logicalSize);
QRectF clipRect = slice.isValid() ? QRectF(slice) : fullRect;
clipRect = clipRect.intersected(fullRect);
if (clipRect.isEmpty()) {
clipRect = fullRect;
}
if (clipRect.width() <= 0.0 || clipRect.height() <= 0.0) {
qCWarning(appLog) << "Invalid clip rectangle for XPS render" << clipRect;
if (logicalSize.isEmpty() || logicalSize.width() <= 0.0 || logicalSize.height() <= 0.0) {
qCWarning(appLog) << "Invalid logical size for XPS page" << logicalSize;
return QImage();
}

const double scaleX = width / clipRect.width();
const double scaleY = height / clipRect.height();
const double pixelsPerDocX = static_cast<double>(width) / logicalSize.width();
const double pixelsPerDocY = static_cast<double>(height) / logicalSize.height();

QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
if (pixelsPerDocX <= 0.0 || pixelsPerDocY <= 0.0) {
qCWarning(appLog) << "Invalid pixels-per-document ratio" << pixelsPerDocX << pixelsPerDocY;
return QImage();
}

const QRect fullSlice(0, 0, width, height);
const QRect requestedSlice = slice.isValid() ? slice : fullSlice;

if (requestedSlice.width() <= 0 || requestedSlice.height() <= 0) {
qCWarning(appLog) << "Requested slice has non-positive size" << requestedSlice;
return QImage();
}

const QSize targetSize(requestedSlice.size());

QImage image(targetSize.width(), targetSize.height(), QImage::Format_ARGB32_Premultiplied);
if (image.isNull()) {
qCWarning(appLog) << "Failed to allocate image for XPS render";
return image;
Expand All @@ -511,8 +520,8 @@ QImage XpsDocumentAdapter::renderPage(int pageIndex, int width, int height, cons

CairoSurfacePtr surface(cairo_image_surface_create_for_data(image.bits(),
CAIRO_FORMAT_ARGB32,
width,
height,
targetSize.width(),
targetSize.height(),
image.bytesPerLine()));
if (!surface || cairo_surface_status(surface.get()) != CAIRO_STATUS_SUCCESS) {
qCWarning(appLog) << "Failed to create Cairo surface for XPS render";
Expand All @@ -529,11 +538,16 @@ QImage XpsDocumentAdapter::renderPage(int pageIndex, int width, int height, cons
cairo_paint(context.get());

cairo_matrix_t matrix;
cairo_set_antialias(context.get(), CAIRO_ANTIALIAS_BEST);

const double translateX = slice.isValid() ? -static_cast<double>(requestedSlice.left()) : 0.0;
const double translateY = slice.isValid() ? -static_cast<double>(requestedSlice.top()) : 0.0;

cairo_matrix_init(&matrix,
scaleX, 0.0,
0.0, scaleY,
-clipRect.left() * scaleX,
-clipRect.top() * scaleY);
pixelsPerDocX, 0.0,
0.0, pixelsPerDocY,
translateX,
translateY);
cairo_set_matrix(context.get(), &matrix);

GErrorPtr renderError;
Expand Down
4 changes: 4 additions & 0 deletions reader/uiframe/DocSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ DocSheet::DocSheet(const Dr::FileType &fileType, const QString &filePath, QWidg
m_sidebar = new SheetSidebar(this, PREVIEW_THUMBNAIL | PREVIEW_BOOKMARK);
else if (Dr::DOCX == fileType)
m_sidebar = new SheetSidebar(this, PREVIEW_THUMBNAIL | PREVIEW_CATALOG | PREVIEW_BOOKMARK | PREVIEW_NOTE);
#ifdef XPS_SUPPORT_ENABLED
else if (Dr::XPS == fileType)
m_sidebar = new SheetSidebar(this, PREVIEW_THUMBNAIL | PREVIEW_CATALOG | PREVIEW_BOOKMARK);
#endif
else
m_sidebar = new SheetSidebar(this);

Expand Down
7 changes: 6 additions & 1 deletion reader/uiframe/TitleWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ void TitleWidget::onCurSheetChanged(DocSheet *sheet)
}

qCDebug(appLog) << "Setting up controls for file type:" << m_curSheet->fileType();
if (Dr::PDF == m_curSheet->fileType() || Dr::DOCX == m_curSheet->fileType()) {
if (Dr::PDF == m_curSheet->fileType()
|| Dr::DOCX == m_curSheet->fileType()
#ifdef XPS_SUPPORT_ENABLED
|| Dr::XPS == m_curSheet->fileType()
#endif
) {
if (m_curSheet->opened()) {
qCDebug(appLog) << "Document opened, enabling controls";
setBtnDisable(false);
Expand Down