Window下编译qtpdfium
Posted ITlsy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 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 OSs. Including aPPLE os x and CygWin")
ENDIF ()
3.修改代码:qpdf\\src\\3rdparty\\pdfium\\core\\fxge\\win32\\fx_win32_dwrite.cpp
typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)(
_In_ DWRITE_FACTORY_TYPE,
_In_ REFIID,
_Out_ IUnknown**);
typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)(
__in DWRITE_FACTORY_TYPE,
__in REFIID,
__out IUnknown**);
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);
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);
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)
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)
4.修改代码qpdf_cmake\\src\\3rdparty\\pdfium\\core\\fxge\\win32\\fx_win32_gdipext.cpp
m_Functions[i] = GetProcAddress(m_hModule, g_GdipFuncNames[i]);
m_Functions[i] = (void*)GetProcAddress(m_hModule, g_GdipFuncNames[i]);
GetProcAddress(m_GdiModule, "AddFontMemResourceEx");
(void*)GetProcAddress(m_GdiModule, "AddFontMemResourceEx");
GetProcAddress(m_GdiModule, "RemoveFontMemResourceEx");
(void*)GetProcAddress(m_GdiModule, "RemoveFontMemResourceEx");
修改完毕,可以执行run cmake,build,run,然后就可以打开pdf啦。
以上是关于Window下编译qtpdfium的主要内容,如果未能解决你的问题,请参考以下文章
Window下编译 64位ffmpeg 引入libx264 libmp3lame库