how to add chinese text

75 views
Skip to first unread message

钟文煜

unread,
May 6, 2024, 11:30:11 AMMay 6
to pdfium
// 读取字体文件
std::ifstream fontFile("Chinese.ttf", std::ios::binary | std::ios::ate);
std::streamsize streamsize = fontFile.tellg();
fontFile.seekg(0, std::ios::beg);
std::vector<uint8_t> fontData(streamsize);
if (!fontFile.read(reinterpret_cast<char*>(fontData.data()), streamsize)) {
return -1;
}

// 加载字体
FPDF_FONT font = FPDFText_LoadFont(p_reader->p_reader_->RawDoc(), fontData.data(), fontData.size(), FPDF_FONT_TRUETYPE, true);
if (font == nullptr) {
return -1;
}

// 创建文本对象
FPDF_PAGEOBJECT text_object3 = FPDFPageObj_CreateTextObj(p_reader->p_reader_->RawDoc(), font, 12.0f);
FPDFText_SetText(text_object3, FPDF_WIDESTRING(rect_type2));
FPDFPageObj_SetFillColor(text_object3, 0, 0, 255, 150);
FPDFPageObj_Transform(text_object3, 1, 0, 0, 1, 200, 600);
FPDFPage_InsertObject(p_page, text_object3);

The above code cannot add Chinese text

Lei Zhang

unread,
May 7, 2024, 1:16:10 PMMay 7
to 钟文煜, pdfium
Both FPDFEditEmbedderTest.EmbedNotoSansSCFontWithCharcodes and
FPDFEditEmbedderTest.EmbedNotoSansSCFont in
fpdfsdk/fpdf_edit_embeddertest.cpp generate PDFs with Chinese text.
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/b5907f50-4881-4d9c-b112-ad0b20ba1476n%40googlegroups.com.

钟文煜

unread,
May 7, 2024, 10:54:33 PMMay 7
to pdfium
pdfium::span<const uint8_t> span = CIDfont.GetFontSpan();
After obtaining the font content, how to filter part of the data, for example, I only need the font data of the word "妈"

Lei Zhang

unread,
May 8, 2024, 11:15:21 AMMay 8
to 钟文煜, pdfium
You'll need to use a font subsetter to do that.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/69379a38-c251-4727-8588-f70402d665ban%40googlegroups.com.
Message has been deleted
Message has been deleted

钟文煜

unread,
May 10, 2024, 4:57:57 AMMay 10
to pdfium
1、load font

企业微信截图_7145ddd3-f0fd-4cc4-9140-7e7c0b357049.png
2、subset
企业微信截图_17794817-d744-4aa0-a22f-ef45cf269d19.png
3、but loca and glypy is null
企业微信截图_9ae9eeb7-3f96-4404-aedb-b3c8f3abfbbe.png
4、Check that loca is normal
企业微信截图_b385dea4-8ceb-4c64-a21f-fb62ac859b8d.png
Reply all
Reply to author
Forward
0 new messages