LoadString with local fonts

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

LoadString with local fonts

Postby NikitaFeodonit » Mon Oct 10, 2016 3:48 am

I try to load the html text from string. The html text contains a style with custom @font-face. The font files are in the folder
/home/user/html
in which are files
NotoSerif-Bold.ttf
NotoSerif-BoldItalic.ttf
NotoSerif-Italic.ttf
NotoSerif-Regular.ttf

My code for it:
Code: Select all
  CefRefPtr<CefFrame> frame = browser->GetMainFrame();

  frame->LoadURL("file:///home/user/html/");

  frame->LoadString(
      R"(
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <style>
      @font-face {
        font-family: 'NotoSerif';
        src: url('NotoSerif-Regular.ttf');
        font-weight: normal;
        font-style: normal;
      }

      body {
        font-family: 'NotoSerif';
      }
      </style>
      </head>
      <body>
      <h1>Test 12345 ⌐ἔγραψα¬</h1>
      </body>
      </html>
      )",
      "about:blank");


Then the html text with its font is loaded correctly.

Is code correct? Or how can I assign the base URL for the html text?
NikitaFeodonit
Newbie
 
Posts: 2
Joined: Mon Oct 10, 2016 3:29 am

Re: LoadString with local fonts

Postby fddima » Mon Oct 10, 2016 9:46 am

Use LoadURL instead of LoadString. It is always better.

To load locally hosted content, you can use custom scheme handlers (note that it is much easier to register custom scheme handler on already exists protocol (i.e. on http) and virtual domain, no network requests will be maden for local content).

Probably easiest way to do it, is by use cef_resource_manager.h.


Or how can I assign the base URL for the html text?

HTML <base> element
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: LoadString with local fonts

Postby NikitaFeodonit » Mon Oct 10, 2016 10:42 am

Thank you! I will try it.
NikitaFeodonit
Newbie
 
Posts: 2
Joined: Mon Oct 10, 2016 3:29 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 59 guests