0

It's pretty easy to embed font to windows phone application, but I cannot find way to use my fonts in WebBrowser control, that is showing static html file. Is there any way to do it?

I'm using code below to show my html file:

        Uri uri = new Uri(AppResources.red_termsOfUse_URI, UriKind.Relative);
        Stream stream = Application.GetResourceStream(uri).Stream;
        using (StreamReader reader = new StreamReader(stream, new System.Text.UnicodeEncoding()))
        {
            string htmlDocument = reader.ReadToEnd();
            this.webBrowser.NavigateToString(htmlDocument);
        }
Thaven
  • 1,857
  • 3
  • 19
  • 35

2 Answers2

2

The webBrowser Control will display the page with the font defined in the css (or style element) of the page. (It will not use the Embedded font)

You can use Javascript to set the Font at runtime OR you can define the font you want inside the HTML file itself (if the file is under your control).

To learn more about Injecting JavaScript in WP7 WebBrowser control read this.

Edit:
If you have access to css then you can also try this to use embedded font (same as we do in any HTML page).

(Not tested)
@font-face {
    font-family: your_font;
    src: local(your_font), url('fonts/bttf.ttf') format('opentype');
}

See this to learn How to Display Local Html page along with Asset. I hope that makes sense, I can't test it right now.

Community
  • 1
  • 1
Ankit
  • 1,471
  • 17
  • 29
  • So, short answer is: There is no way to used Embedded font in WebBrowser Control? – Thaven Sep 05 '12 at 06:16
  • Not exactly. there are some ways, but I want to point that "It can't be done the way we do in any Silverlight page", its more on the HTML and CSS side. – Ankit Sep 05 '12 at 13:34
1

I had to do something similar. One of my friends found part of the suggested solution using CSS, and also Data Url Scheme. Then after some fight I got it working.

In my case, I an using NavigateToString (instead of Navigate to a Url), but I think with some tricks it may work

Sample of custom font in WebBrowser

Because I have found this is tricky I have created a blog post with some code sample:

Here is my blog post: http://hmadrigal.wordpress.com/2014/03/17/how-embed-fonts-in-windows-phone-8-using-a-webbrowser-control/

Here is my code sample: https://github.com/hmadrigal/playground-dotnet/tree/master/MsWinPhone.EmbedFont

Cheers, Herb

hmadrigal
  • 1,020
  • 11
  • 19