Browse Source

static fonts should support explicit space advance specified from font file

David Rose 14 years ago
parent
commit
75ac6c1bae
3 changed files with 19 additions and 5 deletions
  1. 5 0
      models/cmtt12.egg
  2. 13 4
      panda/src/text/staticTextFont.cxx
  3. 1 1
      pandatool/src/egg-mkfont/Sources.pp

+ 5 - 0
models/cmtt12.egg

@@ -1818,6 +1818,11 @@
       0 1 0
     }
   }
+  <Group> 32 {
+    <PointLight> {
+      <VertexRef> { 160 <Ref> { vpool } }
+    }
+  }
   <Group> 33 {
     <Polygon> {
       <TRef> { chars }

+ 13 - 4
panda/src/text/staticTextFont.cxx

@@ -70,6 +70,14 @@ StaticTextFont(PandaNode *font_def) {
 
   find_characters(font_def, RenderState::make_empty());
   _is_valid = !_glyphs.empty();
+  
+  // Check for an explicit space width.
+  int character = 32;
+  Glyphs::iterator gi = _glyphs.find(character);
+  if (gi != _glyphs.end()) {
+    TextGlyph *glyph = (*gi).second;
+    _space_advance = glyph->get_advance();
+  }
 
   set_name(font_def->get_name());
 }
@@ -287,15 +295,16 @@ find_characters(PandaNode *root, const RenderState *net_state) {
     CPT(Geom) dot;
     const RenderState *state = NULL;
     find_character_gsets(root, ch, dot, state, next_net_state);
-    if (ch != (Geom *)NULL && dot != (Geom *)NULL) {
+    PN_stdfloat width = 0.0;
+    if (dot != (Geom *)NULL) {
       // Get the first vertex from the "dot" geoset.  This will be the
       // origin of the next character.
       GeomVertexReader reader(dot->get_vertex_data(), InternalName::get_vertex());
-      PN_stdfloat width = reader.get_data1f();
-
-      _glyphs[character] = new TextGlyph(character, ch, state, width);
+      width = reader.get_data1f();
     }
 
+    _glyphs[character] = new TextGlyph(character, ch, state, width);
+
   } else if (name == "ds") {
     // The group "ds" is a special node that indicates the font's
     // design size, or line height.

+ 1 - 1
pandatool/src/egg-mkfont/Sources.pp

@@ -8,7 +8,7 @@
 #define OTHER_LIBS \
     egg:c pandaegg:m \
     pipeline:c event:c pstatclient:c panda:m \
-    pandabase:c pnmimage:c pnmtext:c \
+    pandabase:c pnmimage:c pnmimagetypes:c pnmtext:c \
     mathutil:c linmath:c putil:c express:c \
     pandaexpress:m \
     interrogatedb:c prc:c dconfig:c dtoolconfig:m \