Browse Source

Font merge demo and documentation minor additions.
Clarifies the lifetime requirements for the ranges parameter for AddFont* functions.

Doug Binks 9 years ago
parent
commit
e1bc0dd7d5
2 changed files with 4 additions and 2 deletions
  1. 1 1
      examples/opengl_example/main.cpp
  2. 3 1
      extra_fonts/README.txt

+ 1 - 1
examples/opengl_example/main.cpp

@@ -33,7 +33,7 @@ int main(int, char**)
     //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
     //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
 
 
     // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
     // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
-    //ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
+    //static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
     //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
     //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
     //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
     //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
     //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
     //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);

+ 3 - 1
extra_fonts/README.txt

@@ -30,7 +30,9 @@
    io.Fonts->AddFontDefault();
    io.Fonts->AddFontDefault();
 
 
    // Add character ranges and merge into main font
    // Add character ranges and merge into main font
-   ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
+   // The ranges array is not copied by the AddFont* functions and is used lazily
+   // so ensure it is available for duration of font usage
+   static const ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
    ImFontConfig config;
    ImFontConfig config;
    config.MergeMode = true;
    config.MergeMode = true;
    io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
    io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);