international font selection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Puls

    international font selection

    I'm writing a Windows Forms application in C# which will run generally in a
    Western environment; e.g., EN-US. I need to access a unicode font on the
    user's system which is capable of displaying Japanese characters - often
    there will be one or more of such fonts, but I don't know which ones by
    name. If one does not exist, I need to default to a public domain font to be
    included with the app.

    How do I determine which fonts are available on the user's system, and if
    they have the required characters? I could come up with a short list of
    probable font name candidates, but is there a better way?

    If there are any references to URLs which have discussed this, that would be
    fine!

    Thanks,

    - Jim


  • Joe White

    #2
    Re: international font selection

    To determine which fonts are available, you can instantiate an
    InstalledFontCo llection object and then read its Families property.
    This will give you an array of FontFamily objects, and FontFamily.Name
    gives you the font name.

    I'm not sure how to detect which characters are available in a font,
    though. I'd be surprised if there wasn't a way to do it, but I didn't
    see it in a quick skim through the docs.


    Jim Puls wrote:[color=blue]
    > I'm writing a Windows Forms application in C# which will run generally in a
    > Western environment; e.g., EN-US. I need to access a unicode font on the
    > user's system which is capable of displaying Japanese characters - often
    > there will be one or more of such fonts, but I don't know which ones by
    > name. If one does not exist, I need to default to a public domain font to be
    > included with the app.
    >
    > How do I determine which fonts are available on the user's system, and if
    > they have the required characters? I could come up with a short list of
    > probable font name candidates, but is there a better way?
    >
    > If there are any references to URLs which have discussed this, that would be
    > fine!
    >
    > Thanks,
    >
    > - Jim
    >
    >[/color]

    Comment

    • Michael \(michka\) Kaplan [MS]

      #3
      Re: international font selection

      Looking specifically for Japanese, you can base it on a font charset value
      of 128?


      --
      MichKa [MS]

      This posting is provided "AS IS" with
      no warranties, and confers no rights.


      "Joe White" <ip255@hotmail. com> wrote in message
      news:3F0113C9.8 080508@hotmail. com...[color=blue]
      > To determine which fonts are available, you can instantiate an
      > InstalledFontCo llection object and then read its Families property.
      > This will give you an array of FontFamily objects, and FontFamily.Name
      > gives you the font name.
      >
      > I'm not sure how to detect which characters are available in a font,
      > though. I'd be surprised if there wasn't a way to do it, but I didn't
      > see it in a quick skim through the docs.
      >
      >
      > Jim Puls wrote:[color=green]
      > > I'm writing a Windows Forms application in C# which will run generally[/color][/color]
      in a[color=blue][color=green]
      > > Western environment; e.g., EN-US. I need to access a unicode font on the
      > > user's system which is capable of displaying Japanese characters - often
      > > there will be one or more of such fonts, but I don't know which ones by
      > > name. If one does not exist, I need to default to a public domain font[/color][/color]
      to be[color=blue][color=green]
      > > included with the app.
      > >
      > > How do I determine which fonts are available on the user's system, and[/color][/color]
      if[color=blue][color=green]
      > > they have the required characters? I could come up with a short list of
      > > probable font name candidates, but is there a better way?
      > >
      > > If there are any references to URLs which have discussed this, that[/color][/color]
      would be[color=blue][color=green]
      > > fine!
      > >
      > > Thanks,
      > >
      > > - Jim
      > >
      > >[/color]
      >[/color]


      Comment

      • Peter Huang [MSFT]

        #4
        RE: international font selection

        Hi Jim,

        There is a GDI API function GetGlyphIndices which will help you very much.
        The function can be used to determine whether a glyph exists in a font.
        Here is a demo below:

        1. Add the class below into your project which is used to call the GDI
        API function.

        public class Win33
        {
        [DllImport("Gdi3 2.dll")]
        public static extern IntPtr SelectObject(
        IntPtr hdc, // handle to DC
        IntPtr hgdiobj // handle to object
        );
        [DllImport("Gdi3 2.dll", CharSet=CharSet .Unicode)]
        public static extern int GetGlyphIndices (
        IntPtr hdc, // handle to DC
        [MarshalAs(Unman agedType.LPWStr )]
        string lpstr, // string to convert
        int c, // number of characters in string
        Int16[] pgi, // array of glyph indices
        int fl // glyph options
        );
        }

        2. In order to get the hdc easier, I hereby override the OnPaint()
        function (as below). You may achieve your individual aim with your own
        method.

        protected override void
        OnPaint(System. Windows.Forms.P aintEventArgs e)
        {
        FontFamily fontFamily = new FontFamily("Ari al");
        Font font = new Font(
        fontFamily,
        14,
        FontStyle.Regul ar,
        GraphicsUnit.Po int);
        System.IntPtr hd = e.Graphics.GetH dc();
        Win33.SelectObj ect(hd,font.ToH font());
        string str = "hello";
        int count = str.Length;
        Int16[] rtcode = new Int16[count];
        Win33.GetGlyphI ndices(hd,str,c ount,rtcode,0xf fff);
        e.Graphics.Rele aseHdc(hd);
        }

        If a certain char is not supported by the font, the
        "rtcode"(as above) will return zero.
        [INFO]
        Here is a helpful link about glyph indices of font.:



        Regards,

        Peter Huang
        =============
        This posting is provided "AS IS" with no warranties, and confers no rights.

        --------------------[color=blue]
        >From: "Jim Puls" <j.puls@ieee.or g>
        >Subject: international font selection
        >Date: Mon, 30 Jun 2003 20:57:36 -0500
        >Lines: 19
        >X-Priority: 3
        >X-MSMail-Priority: Normal
        >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
        >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
        >Message-ID: <uiR2sQ3PDHA.23 16@TK2MSFTNGP11 .phx.gbl>
        >Newsgroups:[/color]
        microsoft.publi c.dotnet.genera l,microsoft.pub lic.dotnet.lang uages.csharp[color=blue]
        >NNTP-Posting-Host: 12-208-112-188.client.attb i.com 12.208.112.188
        >Path: cpmsftngxa09.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
        >Xref: cpmsftngxa09.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:2972 6[/color]
        microsoft.publi c.dotnet.genera l:14254[color=blue]
        >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
        >
        >I'm writing a Windows Forms application in C# which will run generally in a
        >Western environment; e.g., EN-US. I need to access a unicode font on the
        >user's system which is capable of displaying Japanese characters - often
        >there will be one or more of such fonts, but I don't know which ones by
        >name. If one does not exist, I need to default to a public domain font to[/color]
        be[color=blue]
        >included with the app.
        >
        >How do I determine which fonts are available on the user's system, and if
        >they have the required characters? I could come up with a short list of
        >probable font name candidates, but is there a better way?
        >
        >If there are any references to URLs which have discussed this, that would[/color]
        be[color=blue]
        >fine!
        >
        >Thanks,
        >
        >- Jim
        >
        >
        >[/color]

        Comment

        Working...