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
45 changes: 36 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,41 @@ project(deepin-reader
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# XPS支持选项(默认关闭)
option(XPS_SUPPORT "Enable XPS document format support" OFF)
if(XPS_SUPPORT)
message(">>> XPS support enabled")
add_compile_definitions(XPS_SUPPORT_ENABLED)
# XPS支持选项(根据依赖检测自动启用)
find_package(PkgConfig REQUIRED)
option(XPS_SUPPORT "Enable XPS document format support" ON)

set(XPS_SUPPORT_RESOLVED ${XPS_SUPPORT})
set(XPS_DEPS_FOUND OFF)

if (XPS_SUPPORT)
if (PkgConfig_FOUND)
pkg_check_modules(XPS_DEPS QUIET libgxps cairo glib-2.0 gobject-2.0)
if (XPS_DEPS_FOUND)
message(STATUS ">>> XPS support enabled (libgxps dependencies detected)")
add_compile_definitions(XPS_SUPPORT_ENABLED)
set(XPS_SUPPORT_RESOLVED ON)
else()
message(WARNING ">>> XPS support disabled: missing libgxps/cairo/glib-2.0/gobject-2.0 dependencies")
set(XPS_SUPPORT_RESOLVED OFF)
endif()
else()
message(WARNING ">>> XPS support disabled: pkg-config not available")
set(XPS_SUPPORT_RESOLVED OFF)
endif()
else()
message(">>> XPS support disabled")
message(STATUS ">>> XPS support disabled by configuration")
endif()

set(XPS_SUPPORT_ENABLED ${XPS_SUPPORT_RESOLVED})
if (XPS_SUPPORT_ENABLED)
set(XPS_DEPS_INCLUDE_DIRS ${XPS_DEPS_INCLUDE_DIRS})
set(XPS_DEPS_LIBRARIES ${XPS_DEPS_LIBRARIES})
set(XPS_DEPS_CFLAGS_OTHER ${XPS_DEPS_CFLAGS_OTHER})
else()
unset(XPS_DEPS_INCLUDE_DIRS)
unset(XPS_DEPS_LIBRARIES)
unset(XPS_DEPS_CFLAGS_OTHER)
endif()

include(GNUInstallDirs)
Expand All @@ -37,11 +65,10 @@ set(QT_DESIRED_VERSION ${QT_VERSION_MAJOR})
# 设置DTK版本
if (QT_VERSION_MAJOR MATCHES 6)
set(DTK_VERSION_MAJOR 6)
set(PDF_LIB_VERSION "")
else()
set(DTK_VERSION_MAJOR "")
set(PDF_LIB_VERSION 5)
endif()
set(PDF_LIB_VERSION "")
message(">>> Build with DTK: ${DTK_VERSION_MAJOR}")

# 定义必需的Qt组件
Expand Down Expand Up @@ -100,4 +127,4 @@ add_custom_target(${PROJECT_NAME}_qm_files DEPENDS ${QM_FILES})
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_qm_files)

# Install translations
install(FILES ${QM_FILES} DESTINATION share/${PROJECT_NAME}/translations)
install(FILES ${QM_FILES} DESTINATION share/${PROJECT_NAME}/translations)
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Document Viewer realizes basic document management such as opening files, saving

### Open files

Document Viewer supports DOCX, PDF and DJVU formats. You can open a file by:
Document Viewer supports DOCX, PDF, DJVU, and XPS formats. You can open a file by:

- Dragging it directly into the interface or onto the icon.
- Right-clicking it and selecting **Open with** > **Document Viewer**. After setting Document Viewer as the default program, you can open it by double-clicking it directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Document Viewer realizes basic document management such as opening files, saving

### Open files

Document Viewer supports DOCX, PDF and DJVU formats. You can open a file by:
Document Viewer supports DOCX, PDF, DJVU, and XPS formats. You can open a file by:

- Dragging it directly into the interface or onto the icon.
- Right-clicking it and selecting **Open with** > **Document Viewer**. After setting Document Viewer as the default program, you can open it by double-clicking it directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

### 打开文件

文档查看器支持查看PDF、DJVU和DOCX格式的文件,您可以采用以下方式打开文件。
文档查看器支持查看 PDF、DJVU、DOCX、XPS 等格式的文件,您可以采用以下方式打开文件。

- 直接将文件拖拽到界面或其图标上。
- 右键单击文件,选择 **打开方式 > 文档查看器**。将文档查看器设为默认打开程序后,可以直接双击打开。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

### 打开文件

文档查看器支持查看PDF、DJVU和DOCX格式的文件,您可以采用以下方式打开文件。
文档查看器支持查看 PDF、DJVU、DOCX、XPS 等格式的文件,您可以采用以下方式打开文件。

- 直接将文件拖拽到界面或其图标上。
- 右键单击文件,选择 **打开方式 > 文档查看器**。将文档查看器设为默认打开程序后,可以直接双击打开。
Expand Down
7 changes: 5 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ Build-Depends:
libdtk6widget-dev [!mipsel !mips64el] | libdtkwidget-dev,
libdtk6gui-dev [!mipsel !mips64el] | libdtkgui-dev,
libdtk6core-dev [!mipsel !mips64el] | libdtkcore-dev,
libdeepin-pdfium-dev (>= 1.5.1) [!mipsel !mips64el] | libdeepin-pdfium5-dev (>= 1.5.1),
libdeepin-pdfium-dev [!mipsel !mips64el] | libdeepin-pdfium-dev,
libgxps-dev,
libcairo2-dev,
libglib2.0-dev,
libdjvulibre-dev,
libtiff-dev,
libjpeg-dev,
Expand All @@ -35,6 +38,6 @@ Depends:
${shlibs:Depends},
${misc:Depends},
pandoc,
libqt6webenginecore6-bin [!mipsel !mips64el] | libqt5core5a
libqt6webenginecore6-bin [!mipsel !mips64el] | libqt5core5a,
Description: a tool for reading document files.
Document Viewer is a tool for reading document files, supporting PDF, DJVU, DOCX etc.
2 changes: 1 addition & 1 deletion htmltopdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ endif()
# 安装目标
install(TARGETS htmltopdf
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-reader
)
)
2 changes: 1 addition & 1 deletion linglong.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build: |

sources:
# linglong:gen_deb_source sources amd64 http://10.20.64.92:8080/crimson_25.1 stable main
# linglong:gen_deb_source install qt6-base-dev, qt6-base-dev-tools, qt6-tools-dev, libdtk6widget-dev, libspectre-dev, libdjvulibre-dev, libtiff-dev, libjpeg-dev, libicu-dev, libpng-dev, zlib1g-dev, liblcms2-dev, libopenjp2-7-dev, libfreetype6-dev, libgtest-dev, libchardet-dev, qt6-webengine-dev, qt6-5compat-dev, libdtk6gui-dev, libdtk6core-dev, qt6-svg-dev, pandoc, libdeepin-pdfium-dev
# linglong:gen_deb_source install qt6-base-dev, qt6-base-dev-tools, qt6-tools-dev, libdtk6widget-dev, libspectre-dev, libdjvulibre-dev, libtiff-dev, libjpeg-dev, libicu-dev, libpng-dev, zlib1g-dev, liblcms2-dev, libopenjp2-7-dev, libfreetype6-dev, libgtest-dev, libchardet-dev, qt6-webengine-dev, qt6-5compat-dev, libdtk6gui-dev, libdtk6core-dev, qt6-svg-dev, pandoc, libdeepin-pdfium-dev, libgxps-dev, libcairo2-dev, libglib2.0-dev, libgobject-2.0-dev
- kind: file
url: http://10.20.64.92:8080/crimson_25.1/pool/main/q/qt6-tools/assistant-qt6_6.8.0-0deepin3_amd64.deb
digest: 8b5df0b28f8a7cfc63a1ba4ac369f09a66e19d47a462c4bc8fa8bc552f18a714
Expand Down
11 changes: 8 additions & 3 deletions reader/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ Application::Application(int &argc, char **argv)
setApplicationVersion(DApplication::buildVersion(APP_VERSION));
setApplicationAcknowledgementPage("https://www.deepin.org/acknowledgments/deepin_reader");
setApplicationDisplayName(tr("Document Viewer"));
const QStringList supportedFormats = {
QStringLiteral("PDF"),
QStringLiteral("DJVU"),
QStringLiteral("DOCX")
#ifdef XPS_SUPPORT_ENABLED
setApplicationDescription(tr("Document Viewer is a tool for reading document files, supporting PDF, DJVU, DOCX, XPS etc."));
#else
setApplicationDescription(tr("Document Viewer is a tool for reading document files, supporting PDF, DJVU, DOCX etc."));
, QStringLiteral("XPS")
#endif
};
setApplicationDescription(tr("Document Viewer is a tool for reading document files, supporting %1.")
.arg(supportedFormats.join(QStringLiteral(", "))));
setProductIcon(QIcon::fromTheme("deepin-reader"));
}

Expand Down
40 changes: 33 additions & 7 deletions reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBJPEG REQUIRED libjpeg)
pkg_check_modules(DDJVU REQUIRED ddjvuapi)
pkg_check_modules(PDFIUM REQUIRED deepin-pdfium${PDF_LIB_VERSION})
if (XPS_SUPPORT_ENABLED)
pkg_check_modules(XPS_DEPS REQUIRED libgxps cairo glib-2.0 gobject-2.0)
endif()

# 添加位置无关代码编译标志
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
Expand Down Expand Up @@ -75,6 +78,7 @@ target_include_directories(deepin-reader PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/uiframe
${CMAKE_CURRENT_SOURCE_DIR}/widgets
${PDFIUM_INCLUDE_DIRS}
$<$<BOOL:${XPS_SUPPORT_ENABLED}>:${XPS_DEPS_INCLUDE_DIRS}>
)

if (NOT APP_VERSION)
Expand All @@ -87,18 +91,40 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
APP_VERSION="${APP_VERSION}"
)

# 链接库
target_link_libraries(deepin-reader PRIVATE
if (XPS_SUPPORT_ENABLED)
target_compile_options(deepin-reader PRIVATE ${XPS_DEPS_CFLAGS_OTHER})
endif()

# 添加资源文件
set(READER_LINK_LIBS
${LINK_LIBS}
${LIBJPEG_LIBRARIES}
${DDJVU_LIBRARIES}
${PDFIUM_LIBRARIES}
)

# 添加资源文件
qt_add_resources(reader_RESOURCES
${CMAKE_SOURCE_DIR}/resources/resources.qrc
)
if (XPS_SUPPORT_ENABLED)
list(APPEND READER_LINK_LIBS ${XPS_DEPS_LIBRARIES})
endif()

if (QT_VERSION_MAJOR MATCHES 6)
target_link_libraries(deepin-reader PRIVATE ${READER_LINK_LIBS})

qt_add_resources(reader_RESOURCES
${CMAKE_SOURCE_DIR}/resources/resources.qrc
)
else()
target_link_libraries(deepin-reader PRIVATE
${READER_LINK_LIBS}
dl
pthread
)

qt5_add_resources(reader_RESOURCES
${CMAKE_SOURCE_DIR}/resources/resources.qrc
)
endif()

target_sources(deepin-reader PRIVATE ${reader_RESOURCES})

# 安装目标
Expand Down Expand Up @@ -140,4 +166,4 @@ if(DEFINED DSG_DATA_DIR)
else()
install(FILES ${DCONFIG_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${DCONFIG_APPID})
message("-- DConfig is not supported by DTK")
endif()
endif()
14 changes: 8 additions & 6 deletions reader/browser/BrowserPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ void BrowserPage::render(const double &scaleFactor, const Dr::Rotation &rotation

task.pixmapId = m_pixmapId;

task.rect = QRect(0, 0,
static_cast<int>(boundingRect().width() * dApp->devicePixelRatio()),
static_cast<int>(boundingRect().height() * dApp->devicePixelRatio()));
const qreal deviceRatio = dApp ? dApp->devicePixelRatio() : 1.0;
const int targetWidth = qMax(1, qRound(boundingRect().width() * deviceRatio));
const int targetHeight = qMax(1, qRound(boundingRect().height() * deviceRatio));
task.rect = QRect(0, 0, targetWidth, targetHeight);

PageRenderThread::appendTask(task);
} else {
Expand All @@ -266,9 +267,10 @@ void BrowserPage::render(const double &scaleFactor, const Dr::Rotation &rotation

task.pixmapId = m_pixmapId;

task.rect = QRect(0, 0,
static_cast<int>(boundingRect().width() * dApp->devicePixelRatio()),
static_cast<int>(boundingRect().height() * dApp->devicePixelRatio()));
const qreal deviceRatio = dApp ? dApp->devicePixelRatio() : 1.0;
const int targetWidth = qMax(1, qRound(boundingRect().width() * deviceRatio));
const int targetHeight = qMax(1, qRound(boundingRect().height() * deviceRatio));
task.rect = QRect(0, 0, targetWidth, targetHeight);

PageRenderThread::appendTask(task);
}
Expand Down
16 changes: 15 additions & 1 deletion reader/browser/PageRenderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#include "PageRenderThread.h"
#include "BrowserPage.h"
#include "SheetBrowser.h"
#include "DocSheet.h"

Check warning on line 9 in reader/browser/PageRenderThread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DocSheet.h" not found.
#include "SheetRenderer.h"

Check warning on line 10 in reader/browser/PageRenderThread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "SheetRenderer.h" not found.
#include "SideBarImageViewModel.h"

Check warning on line 11 in reader/browser/PageRenderThread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "SideBarImageViewModel.h" not found.
#include "Application.h"

Check warning on line 12 in reader/browser/PageRenderThread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Application.h" not found.
#include "ddlog.h"

Check warning on line 13 in reader/browser/PageRenderThread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ddlog.h" not found.

#include <QTime>

Check warning on line 15 in reader/browser/PageRenderThread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>
#include <QMetaType>
#include <QFileInfo>
Expand Down Expand Up @@ -594,7 +595,20 @@
return true;
}

QImage image = task.sheet->getImage(task.page->itemIndex(), task.rect.width(), task.rect.height());
int targetWidth = task.rect.width();
int targetHeight = task.rect.height();
if (targetWidth <= 0 || targetHeight <= 0) {
const qreal deviceRatio = dApp ? dApp->devicePixelRatio() : 1.0;
const double pageScale = (task.page && task.page->m_scaleFactor > 0.0)
? task.page->m_scaleFactor
: (task.sheet ? task.sheet->operation().scaleFactor : 1.0);
const QSizeF pageSize = task.page ? task.page->m_originSizeF : QSizeF();
targetWidth = qMax(1, qRound(pageSize.width() * pageScale * deviceRatio));
targetHeight = qMax(1, qRound(pageSize.height() * pageScale * deviceRatio));
task.rect = QRect(0, 0, targetWidth, targetHeight);
}

QImage image = task.sheet->getImage(task.page->itemIndex(), targetWidth, targetHeight);

if (image.isNull()) {
qCWarning(appLog) << "Failed to get image for page:" << task.page->itemIndex();
Expand Down
2 changes: 1 addition & 1 deletion reader/deepin-reader.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Categories=Office;
Exec=deepin-reader %F
GenericName=Document Viewer
Icon=deepin-reader
MimeType=application/pdf;image/vnd.djvu;image/vnd.djvu+multipage;application/wps-office.docx;application/vnd.openxmlformats-officedocument.wordprocessingml.document;
MimeType=application/pdf;image/vnd.djvu;image/vnd.djvu+multipage;application/wps-office.docx;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.ms-xpsdocument;application/oxps;
Name=Document Viewer
StartupNotify=true
TryExec=deepin-reader
Expand Down
4 changes: 2 additions & 2 deletions reader/document/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Model.h"
#ifdef XPS_SUPPORT_ENABLED
#include "XpsDocument.h"
#include "XpsDocumentAdapter.h"
#endif
#include "PDFModel.h"
#include "DjVuModel.h"
Expand Down Expand Up @@ -68,7 +68,7 @@ deepin_reader::Document *deepin_reader::DocumentFactory::getDocument(const int &
#ifdef XPS_SUPPORT_ENABLED
} else if (Dr::XPS == fileType) {
qCDebug(appLog) << "Handling XPS document";
document = deepin_reader::XpsDocument::loadDocument(filePath, error);
document = deepin_reader::XpsDocumentAdapter::loadDocument(filePath, error);
#endif
} else if (Dr::DOCX == fileType) {
qCDebug(appLog) << "Starting DOCX document conversion process";
Expand Down
Loading