Window下编译qtpdfium

14 篇文章 1 订阅
9 篇文章 1 订阅

系统环境:windows11

Qt版本:Qt5.15.2

源代码路径:https://codeload.github.com/kkzi/qpdf/zip/2681018e300738d6da9a9f89f06c93fc3ef17831

下载下来后,直接用MSVC2019编译器的CMake环境编译,顺利通过。但是使用Mingw编译器编译的时候,却出现了一堆错误。错误就不截图了,现在已经把坑全部填平,懒得再返回去了。接下来直接贴出要修改的地方

1.修改qpdf\CMakeLists.txt

#在代码
set(CMAKE_DEBUG_POSTFIX d)
#后面,添加下面代码

if(CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") #设置编译C++文件时,使用c++11
    message(STATUS "optional:-std=c++11")
endif(CMAKE_COMPILER_IS_GNUCXX)

IF (WIN32)
    MESSAGE(STATUS "Now is windows")
    add_compile_options(-shared -fPIC) 
ELSEIF (APPLE)
    MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
    MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x  and CygWin")
    add_compile_options(-std=c++11 -shared -fPIC) #linux下必须要添加编译选项-fPIC,要不然提示错误
ENDIF ()

 2.修改qpdf\src\3rdparty\CMakeLists.txt

#注释掉下面代码
#if(MSVC)
#    list(APPEND PDFIUM_SOURCES
#        pdfium/core/fxge/win32/fx_win32_device.cpp
#        pdfium/core/fxge/win32/fx_win32_dib.cpp
#        pdfium/core/fxge/win32/fx_win32_dwrite.cpp
#        pdfium/core/fxge/win32/fx_win32_gdipext.cpp
#        pdfium/core/fxge/win32/fx_win32_print.cpp
#    )

#    list(APPEND PDFIUM_HEADERS
#        pdfium/core/fxge/win32/dwrite_int.h
#        pdfium/core/fxge/win32/win32_int.h
#    )
#endif(MSVC)

#添加下列代码
IF (WIN32)
    add_definitions(-DCOMPILE_SAL_MINGW) #增加预编译宏,等下在代码修改里要用到
    MESSAGE(STATUS "Now is windows")
    list(APPEND PDFIUM_SOURCES
        pdfium/core/fxge/win32/fx_win32_device.cpp
        pdfium/core/fxge/win32/fx_win32_dib.cpp
        pdfium/core/fxge/win32/fx_win32_dwrite.cpp
        pdfium/core/fxge/win32/fx_win32_gdipext.cpp
        pdfium/core/fxge/win32/fx_win32_print.cpp
    )

    list(APPEND PDFIUM_HEADERS
        pdfium/core/fxge/win32/dwrite_int.h
        pdfium/core/fxge/win32/win32_int.h
    )

ELSEIF (APPLE)
    MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
    MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x  and CygWin")
ENDIF ()

3.修改代码:qpdf\src\3rdparty\pdfium\core\fxge\win32\fx_win32_dwrite.cpp 

#
# 修改函数:HRESULT(__stdcall* FuncType_DWriteCreateFactory)为下面
# 大概位置14行
#

#ifdef COMPILE_SAL_MINGW
typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)(
    _In_ DWRITE_FACTORY_TYPE,
    _In_ REFIID,
    _Out_ IUnknown**);
# else
typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)(
    __in DWRITE_FACTORY_TYPE,
    __in REFIID,
    __out IUnknown**);
#endif

#
# 修改函数:HRESULT STDMETHODCALLTYPE DrawGlyphRun(const FX_RECT& text_bbox为下面
# 大概位置120行
#

#ifdef COMPILE_SAL_MINGW
  HRESULT STDMETHODCALLTYPE DrawGlyphRun(const FX_RECT& text_bbox,
                                         __in_opt CFX_ClipRgn* pClipRgn,
                                         __in_opt DWRITE_MATRIX const* pMatrix,
                                         FLOAT baselineOriginX,
                                         FLOAT baselineOriginY,
                                         DWRITE_MEASURING_MODE measuringMode,
                                         _In_ DWRITE_GLYPH_RUN const* glyphRun,
                                         const COLORREF& textColor);
# else
  HRESULT STDMETHODCALLTYPE DrawGlyphRun(const FX_RECT& text_bbox,
                                         __in_opt CFX_ClipRgn* pClipRgn,
                                         __in_opt DWRITE_MATRIX const* pMatrix,
                                         FLOAT baselineOriginX,
                                         FLOAT baselineOriginY,
                                         DWRITE_MEASURING_MODE measuringMode,
                                         __in DWRITE_GLYPH_RUN const* glyphRun,
                                         const COLORREF& textColor);
#endif



#
# 修改函数:STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(为下面
# 大概位置431行
#

#ifdef COMPILE_SAL_MINGW

STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
    const FX_RECT& text_bbox,
    __in_opt CFX_ClipRgn* pClipRgn,
    __in_opt DWRITE_MATRIX const* pMatrix,
    FLOAT baselineOriginX,
    FLOAT baselineOriginY,
    DWRITE_MEASURING_MODE measuringMode,
    _In_ DWRITE_GLYPH_RUN const* glyphRun,
    const COLORREF& textColor) {
# else
STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
    const FX_RECT& text_bbox,
    __in_opt CFX_ClipRgn* pClipRgn,
    __in_opt DWRITE_MATRIX const* pMatrix,
    FLOAT baselineOriginX,
    FLOAT baselineOriginY,
    DWRITE_MEASURING_MODE measuringMode,
    __in DWRITE_GLYPH_RUN const* glyphRun,
    const COLORREF& textColor) {
#endif

 4.修改代码qpdf_cmake\src\3rdparty\pdfium\core\fxge\win32\fx_win32_gdipext.cpp


# 694行

m_Functions[i] = GetProcAddress(m_hModule, g_GdipFuncNames[i]);

# 修改成

m_Functions[i] = (void*)GetProcAddress(m_hModule, g_GdipFuncNames[i]);


# 709行

GetProcAddress(m_GdiModule, "AddFontMemResourceEx");

# 修改成

(void*)GetProcAddress(m_GdiModule, "AddFontMemResourceEx");


# 711行

GetProcAddress(m_GdiModule, "RemoveFontMemResourceEx");

# 修改成

(void*)GetProcAddress(m_GdiModule, "RemoveFontMemResourceEx");

 修改完毕,可以执行run cmake,build,run,然后就可以打开pdf啦。

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liu-Eleven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值