English 中文(简体)
图1
原标题:Install Type 1 Font in VS 2010 Setup Project

Im试图利用“2010年视觉演播室”设计项目,将一套类型1的字体纳入一个微型卫星定位系统,以便于安装。

I ve 配置了我的安装项目,把所有PFM和PFB档案放在Fonts的夹中,将所有PFM文件编为vsdrfFont,并确定此处提及的命名问题:

http://cjwdev.wordpress.com/201103/14/installing-non-truetype-fonts-with-udio-ststaller/

然而,这只字体为1型字体。

The Type 1 font files are installed but the font is still not recognized and doesn t appear in the Fonts window.

If installed manually, Type 1 fonts are registered under HKLMSOFTWAREMicrosoftWindows NTCurrentVersionType 1 InstallerType 1 Fonts and work fine.

How can the same result be achieved with a setup project?

最佳回答

Here is a solution that involves an MSI custom action. I have written in using C#, but any other language capable of calling a DLL can be user. Here is a tutorial link for C#: Walkthrough: Creating a Custom Action

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.IO;
using System.Runtime.InteropServices;

namespace InstallType1Font
{
    [RunInstaller(true)]
    public partial class Installer1 : Installer
    {
        public Installer1()
        {
            InitializeComponent();
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);

            // here, you ll have to determine the proper path
            string path = @"c:WindowsFontsMyFont.pfm";
            if (File.Exists(path))
            {
                InstallFontFile(IntPtr.Zero, path, 0);
            }
        }

        [DllImport("fontext.dll", CharSet = CharSet.Auto)]
        private static extern void InstallFontFile(IntPtr hwnd, string filePath, int flags);

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }
    }
}

As far as I know, InstallFontFile is undocumented, but allows to install the font permanently. Use this at your own risk.

Note: you still need to modify the .MSI to ensure the Fonts file have a FontTitle as described in the link you gave.

问题回答

安装类型1的字体如下:

  1. Register the font title under Type 1 Fonts
  2. Copy both the PFM and the PFB to the windows fonts directory
  3. Call the AddFontResource method

Register the font title under Type 1 Fonts

SOFTWAREMicrosoftWindows NTCurrentVersionType 1 InstallerType 1 Fonts

The Font Title is required, rather than providing this to the installer, the following code snippet will allow you to read the font title from the PFM. It is based on information gathered from the following source:

rel=“nofollow” http://partners.adobe.com/public/developer/en/font/5178.PFM.pdf

    private static string GetType1FontName(string filename)
    {
        StringBuilder postscriptName = new StringBuilder();

        FileInfo fontFile = new FileInfo(filename);
        using (FileStream fs = fontFile.OpenRead())
        {
            using (StreamReader sr = new StreamReader(fs))
            {
                using (BinaryReader inStream = new BinaryReader(fs))
                {
                    // PFM Header is 117 bytes
                    inStream.ReadBytes(117); // skip 117
                    short size = inStream.ReadInt16();
                    int extMetricsOffset = inStream.ReadInt32();
                    int extentTableOffset = inStream.ReadInt32();

                    inStream.ReadBytes(4); // skip 4
                    int kernPairOffset = inStream.ReadInt32();
                    int kernTrackOffset = inStream.ReadInt32();
                    int driverInfoOffset = inStream.ReadInt32();

                    fs.Position = driverInfoOffset;
                    while (inStream.PeekChar() != 0)
                    {
                        postscriptName.Append(inStream.ReadChar());
                    }
                }
            }
        }

        return postscriptName.ToString();
    }

www.un.org/Depts/DGACM/index_spanish.htm 将PFM和PFB复制到窗户长

根据这一博客, 找到窗户的正确途径如下:

    [DllImport("shell32.dll")]
    private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken,
               uint dwFlags, [Out] StringBuilder pszPath);

    public static string GetFontFolderPath()
    {
        StringBuilder sb = new StringBuilder();
        SHGetFolderPath(IntPtr.Zero, 0x0014, IntPtr.Zero, 0x0000, sb);

        return sb.ToString();
    }

www.un.org/Depts/DGACM/index_spanish.htm 添加FontResource方法

最后,应当称作“AddFontResource”的方法,即直径电离层名称应当由管道星号分离的pfm和pfb文档组成。 在我的案件中,我把通向似乎行之有效的窗户的足迹。 在打电话给AddFontResource之后,你需要用WM的参数打电话。 FONTCHANGE(0x001D)向其他变化窗口提供信息。

    [DllImport("gdi32.dll")]
    static extern int AddFontResource(string lpFilename);

    // build the name for the api "<pfm>|<pfb>"
    string apiValue = string.Format("{0}|{1}", PfmFileDestination, PfbFileDestination);

    // Call the api to register the font
    int retVal = AddFontResource(apiValue);

    // Inform other windows of change
    PostMessage(HWND_BROADCAST, WM.FONTCHANGE, IntPtr.Zero, IntPtr.Zero);




相关问题
Java (AWT): fitting text in a box

I have an application that extends a Frame. Then, it ll display a few lines of text using: Font f = new Font("Arial", Font.PLAIN, 10); g.setFont(f); g.drawString("Test|great Yes ^.", x, y + 10); Now ...

Embed font into PDF file by using iText

I defined a tag map, and got a XML data file. I want to convert the XML data file to PDF by using iText. The question is how to embed fonts (e.g. Polish font, Chinese font) into the target PDF when ...

Font Rendering between Mozilla and webkit

I m not sure if this has anything to do with the recent Safari update, but I m beginning to notice this a lot. There is a drastic difference in the way each browser is rendering fonts. for instance, ...

Embedding Fonts in AS3 - Dynamic Text Field disappears

This is hopefully a new problem or just me missing something obvious. Please help! I m embedding a font into my AS3 application. I m doing everything by-the-book and it half-works. In my main class, ...

Dynamic GD image width text

I m trying to spice up my website by using custom fonts for headings. For me, the most appropriate way to do this is using PHP and GD. I have written a little script which will output the dynamic text ...

How do I combine @font-face and @media declarations?

I d like to build a common typography stylesheet with a very small number of selectors. As such, I d far prefer to use @media sections for the various versions rather than create different files, each ...

热门标签