void GLTEXT_CALL AbstractRenderer::render(const char* text)
   {
      const int ascent  = mFont->getAscent();
      const int descent = mFont->getDescent();
      const int height  = ascent + descent + mFont->getLineGap();

      int penX = 0;
      int penY = 0;

      unsigned char last_character = 0;

      // Run through each char and generate a glyph to draw
      for (const char* itr = text; *itr; ++itr)
      {
         // newline?
         if (*itr == '\n')
         {
            penX = 0;
            penY += height;
            continue;
         }

         // Get the glyph for the current character
         Glyph* fontGlyph = mFont->getGlyph(*itr);
         if (!fontGlyph)
         {
            continue;
         }

         // Check the cache first
         GLGlyph* drawGlyph = mCache.get(fontGlyph);
         if (!drawGlyph)
         {
            // Cache miss. Ask this renderer to create a new one
            drawGlyph = makeGlyph(fontGlyph);
            if (!drawGlyph)
            {
               // AAACK! Couldn't create the glyph. Fail silently.
               continue;
            }
            mCache.put(fontGlyph, drawGlyph);
         }

         int kerning = mFont->getKerning(last_character, *itr);
         last_character = *itr;
         int old_x = penX;
         penX += kerning;

         // Now tell the glyph to render itself.
         drawGlyph->render(penX, penY);
         penX += fontGlyph->getAdvance();

         // Kerning shouldn't make us draw farther and farther to the
         // left...  this fixes the "sliding dot problem".
         penX = std::max(penX, old_x);
      }
   }
Exemple #2
0
  bool CPUFontBase::checkGlyph(unsigned int characterCode)
  {
    Radiant::Guard g( & m_mutex);

    if(m_glyphList->glyph(characterCode) == 0)
    {
        unsigned int glyphIndex = m_glyphList->fontIndex(characterCode);
        Glyph * tempGlyph = makeGlyph(glyphIndex);
        if(tempGlyph == 0) {
            if(m_error == 0)
                m_error = 0x13;

            return false;
        }
        
        m_glyphList->add(tempGlyph, characterCode);
    }

    return true;
  }