不操千曲而后晓声,观千剑而后识器。这篇文章主要讲述Window下编译qtpdfium相关的知识,希望能为你提供帮助。
【Window下编译qtpdfium】
系统环境: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 OSs. Including aPPLE os xand 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 OSs. Including aPPLE os xand 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啦。
推荐阅读
- Spring Cloud 入门 -- 搭建Eureka注册中心 实现服务者与消费者的服务调用
- linux之字符设备驱动
- 超详细解释从Java NIO到Netty的每一步
- Ubuntu20.04基于QT5.15.2搭建android环境
- 6个解决方案(如何在Windows 11上修复鼠标延迟的问题())
- 升级到Windows 11后桌面图标消失如何修复(解决办法)
- android WIFI 设置代理代码 4.4.3——5.0
- 在状态栏增加图标(Android 6.0)
- Android Studio Plugins