Qt编译和使用freetype矢量字库方法

发布于:2024-05-16 ⋅ 阅读:(75) ⋅ 点赞:(0)

在之前讲过QT中利用freetype提取字库生成图片的方法:

#QT利用freetype提取字库图片_qt freetype-CSDN博客文章浏览阅读1.2k次。这是某个项目中要用到的片段,结合上一篇文章#QT从字体名获取字库文件路径使用// 保存位图int SaveBitmapToFile(HBITMAP hBitmap, LPSTR lpFileName){HDC hDC;int iBits;WORD wBitCount; DWORD dwPaletteSize=0,dwBmBitsSize,dwDIBSize_qt freetypehttps://blog.csdn.net/wangningyu/article/details/109743104

QT在场景中利用freetype实现独立的文字绘制子类QxFreeTypeTextItem-CSDN博客QT在场景中利用freetype实现独立的文字绘制子类QxFreeTypeTextItem,继上一章节讲过qt中如何编译freetype。https://blog.csdn.net/wangningyu/article/details/138927884

忘记说如何编译了,通常我们会将freetype编译成一个动态库,这样可以供以后的qt其他工程直接调用,免得每次COPY一堆比较麻烦,下面将告诉大家如何编译成DLL库:

 1、先下载freetype源码,当前版本是2.13.2最新的:

The FreeType Project - Browse /freetype2 at SourceForge.net

2、按照下面的步骤,新建一个dll工程:

这里的名称将是你以后DLL库的名称:

这里根据自己的需要勾选:

后面都是默认下一步完成即可,下载后解压至QT DLL工程目录

此时只需要打开.pro文件,COPY下面这一份即可:

QT -= gui

TEMPLATE = lib
DEFINES += FREETYPE_LIBRARY

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    freetype.cpp

HEADERS += \
    FreeType_global.h \
    freetype.h

# 这里开始COPY即可
DEFINES += FT2_BUILD_LIBRARY
DEFINES += WIN32
DEFINES += _LIB
DEFINES += _CRT_SECURE_NO_WARNINGS
DEFINES += FT_DEBUG_LEVEL_ERROR
DEFINES += FT_DEBUG_LEVEL_TRACE

INCLUDEPATH += \
    freetype-2.13.2/include/

# 这里需要注意下载存放的路径freetype-2.13.2与.pro文件同级目录
SOURCES += \
    freetype-2.13.2/src/ftdebug.c \
    freetype-2.13.2/src/ftsystem.c \
    freetype-2.13.2/src/autofit/autofit.c \
    freetype-2.13.2/src/base/ftbase.c \
    freetype-2.13.2/src/base/ftbbox.c \
    freetype-2.13.2/src/base/ftbdf.c \
    freetype-2.13.2/src/base/ftbitmap.c \
    freetype-2.13.2/src/base/ftcid.c \
    freetype-2.13.2/src/base/ftfstype.c \
    freetype-2.13.2/src/base/ftgasp.c \
    freetype-2.13.2/src/base/ftglyph.c \
    freetype-2.13.2/src/base/ftgxval.c \
    freetype-2.13.2/src/base/ftinit.c \
    freetype-2.13.2/src/base/ftmm.c \
    freetype-2.13.2/src/base/ftotval.c \
    freetype-2.13.2/src/base/ftpatent.c \
    freetype-2.13.2/src/base/ftpfr.c \
    freetype-2.13.2/src/base/ftstroke.c \
    freetype-2.13.2/src/base/ftsynth.c \
    freetype-2.13.2/src/base/fttype1.c \
    freetype-2.13.2/src/base/ftwinfnt.c \
    freetype-2.13.2/src/bdf/bdf.c \
    freetype-2.13.2/src/cache/ftcache.c \
    freetype-2.13.2/src/cff/cff.c \
    freetype-2.13.2/src/cid/type1cid.c \
    freetype-2.13.2/src/dlg/dlgwrap.c \
    freetype-2.13.2/src/gzip/ftgzip.c \
    freetype-2.13.2/src/lzw/ftlzw.c \
    freetype-2.13.2/src/pcf/pcf.c \
    freetype-2.13.2/src/pfr/pfr.c \
    freetype-2.13.2/src/psaux/psaux.c \
    freetype-2.13.2/src/pshinter/pshinter.c \
    freetype-2.13.2/src/psnames/psmodule.c \
    freetype-2.13.2/src/raster/raster.c \
    freetype-2.13.2/src/sfnt\sfnt.c \
    freetype-2.13.2/src/smooth\smooth.c \
    freetype-2.13.2/src/sdf\sdf.c \
    freetype-2.13.2/src/svg\svg.c \
    freetype-2.13.2/src/truetype/truetype.c \
    freetype-2.13.2/src/type1/type1.c \
    freetype-2.13.2/src/type42/type42.c \
    freetype-2.13.2/src/winfonts/winfnt.c \

# 这里复制结束

# Default rules for deployment.
unix {
    target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target

这里基本上就编译成功,没什么问题了

release目录会生成FreeType.dll与FreeType.o文件,即可供其他程序调用。

下面是其他调用freetype工程的pro文件可以参考一下:

QT += gui

TEMPLATE = lib
DEFINES += MTFREETYPE_LIBRARY
CONFIG += dll
CONFIG += c++11
DESTDIR = ../Bin

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
# disables all the APIs deprecated before Qt 6.0.0

# 这里需要注意根据你的实际情况来设定
INCLUDEPATH += \
    ../FreeType/freetype-2.13.2/include/

SOURCES += \
    mtfreetype.cpp \

HEADERS += \
    MTFreeType_global.h \
    mtfreetype.h \

# 这里需要链接你的.o文件所在路径
LIBS += -L../Bin/ -lFreeType

LIBS += -luser32
LIBS += -lgdi32



# Default rules for deployment.
unix {
    target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target