how to use custom fonts in html/css as i want to display it into webview later for Metro windows 8 XAML application.-Collection of common programming errors
Hi Web,
Once you have installed your WOFF files in your app (ensure they are marked as content) you simply need to override the style of the types you wish to change. Note that you may need to parse the HTML to remove stylesheet links, and style overrides (but that is just basic HTML CSS knowledge right).
Here is a simple sample of the code you could use:
// the style we want to inject string theStyle = "@font-face { font-family: GentiumPlusW; src: url(GentiumPlus-R.woff); } /* use Gentium Plus - Italic in .woff format */ @font-face { font-family: GentiumPlusW; font-style: italic; src: url(GentiumPlus-I.woff); } body { font-family: GentiumPlusW, sans-serif; } h1 { font-weight: normal; }"; // create the HttpClient HttpClient theClient = new HttpClient(); // get the body as a string string theResponse = await theClient.GetStringAsync(theTextBox.Text); // find the closing head tag (if it exists) int indexOfClosingHead = theResponse.IndexOf(""); if (indexOfClosingHead > 0) { //insert the stylesheet before the closing head tag so it is the last style read string newString = theResponse.Insert(indexOfClosingHead , theStyle); theWebView.NavigateToString(newString); } // if it does not exist, creat one
I uses this url to test since it had no existing style:
http://www.columbia.edu/~fdc/sample.html
-Jeff