简体   繁体   English

是否有 windows GetFontData function 的 Mac OSX 版本?

[英]Is there a Mac OSX version of windows GetFontData function?

We have an application that allows our users to generate print-ready PDF documents using variable data (names, titles, phone numbers, etc) that their customer's enter via an online e-commerce website.我们有一个应用程序,允许我们的用户使用客户通过在线电子商务网站输入的可变数据(姓名、标题、电话号码等)生成可打印的 PDF 文档。 To facilitate the variable data we have to embed a font's entire character map.为了方便可变数据,我们必须嵌入字体的整个字符 map。 On windows we have been using the windows API function GetFontData(...) like so:在 windows 上,我们一直在使用 windows API ZC1C425268E68385D1AB507FontC17A 等:

#ifdef Q_WS_WIN
    //this is windows specific code
    HDC DC = CreateCompatibleDC(NULL);
    HFONT hFont = font.handle();
    HFONT oFont=(HFONT)SelectObject(DC,hFont);

    DWORD fontLength = ::GetFontData(DC, 0, 0, 0, 0);

    if(fontLength != GDI_ERROR)
    {
        fontData.GrowAllocation(fontLength);

        if(::GetFontData(DC, 0, 0, fontData.GetBuffer(), fontLength) == GDI_ERROR)
        {
            fontData.Clear();
        }
        else
        {
            fontData.SetLength(fontLength);
            returnVal = true;
        }
    }

    SelectObject(DC,oFont);
    DeleteDC(DC);
    //End of windows specific code
#elif defined(Q_WS_MAC)



#endif

This technique works very successfully on our windows specific version;这种技术在我们的 windows 特定版本上非常成功; however, we are porting the application to Qt to target the Mac OSX platform.但是,我们正在将应用程序移植到 Qt 以针对 Mac OSX 平台。

My first question: Is there a Qt way of accessing the raw font data from a QFont, QFontDatabase, etc. that we could use to embed in the pdf?我的第一个问题:是否有一种 Qt 方法可以访问来自 QFont、QFontDatabase 等的原始字体数据,我们可以使用它来嵌入 pdf? We have been unable to find a way.我们一直找不到方法。 Notice the #ifdef wrapper in the above code.注意上面代码中的#ifdef 包装器。 Note that the variable fontData is a self contained memory buffer that manages its own memory, please disregard.请注意,变量 fontData 是一个自包含的 memory 缓冲区,它管理自己的 memory,请忽略。

My second question: If there is no Qt way of accessing the font data in an OS agnostic way, what is the OSX equivalent to the windows GetFontData?我的第二个问题:如果没有 Qt 以与操作系统无关的方式访问字体数据的方式,那么与 windows GetFontData 等效的 OSX 是什么?

Thanks谢谢

I've only skimmed documentation for GetFontData , and I don't know much about Qt (though it does sound like a Qt solution would be preferable), but you might want to look at the ObjC class for fonts, NSFont . I've only skimmed documentation for GetFontData , and I don't know much about Qt (though it does sound like a Qt solution would be preferable), but you might want to look at the ObjC class for fonts, NSFont .

The latest (until Apple hires new font people and gets infected with not-invented-here disease again) text and font API is Core Text .最新的(直到 Apple 雇用新的字体人员并再次感染非发明疾病)文本和字体 API 是Core Text I never used it since chasing Apple's mood is harmful to my personal and organization's financial health, I stopped using any Apple-only API.我从来没有使用过它,因为追逐 Apple 的情绪对我个人和组织的财务健康有害,我停止使用任何 Apple 专用的 API。 :) :)

Kidding aside, it looks like CTFont does provide access to all tables in a font.开个玩笑,看起来CTFont确实提供了对字体中所有表格的访问。 I don't see anything that prepares a font for embedding but this probably gives you the best chance.我没有看到任何准备嵌入字体的东西,但这可能会给你最好的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM