Logo Search packages:      
Sourcecode: yudit version File versions

SS_GlyphIndex SFontTTF::findGlyph ( SS_UCS4  in,
bool  ownjoiners = true 
)

Find one single glyph.

Returns:
the index or 0. TODO: SFontTTF currently handles TTF_CMAP_FMT4 only. This can encode 16 bit unicode only. Make it handle format 8 Mixed 16 bit and 32 bit coverage using Surrogates(U+D800-U+DFFF) format 10 Trimmed Array using Surrogates (U+D800-U+DFFF) format 12 Segmented Coverage using Surrogates (U+D800-U+DFFF) I am not aware of any other format that does not used this MS surrogate hack. (Guess why are these ugly surrogates in Unicode ? :) /param ownjoiners is true if we use our own SD_G_INDIC_ZWJ and SD_G_INDIC_ZWNJ

Definition at line 2277 of file SFontTTF.cpp.

References SBinVector< Type >::size().

Referenced by findGlyphs(), findJamoGlyphs(), findSouthIndicGlyphs(), getBaseOffsets(), and gindex().

{
  /* Support only BMP for now */
  if (in == SD_CD_ZWJ && ownjoiners) return SD_G_INDIC_ZWJ;
  if (in == SD_CD_ZWNJ && ownjoiners) return SD_G_INDIC_ZWNJ;
  /* Experimental filters for whole ranges */
  switch (hardWire)
  { 
  case SS_INDIC:
    if (in<0x0900 || in>0x0FFF) return 0;
    break;
  case SS_DEVANAGARI:
    if (in<0x0900 || in>0x097F) return 0;
    break;
  case SS_BENGALI:
    if (in<0x0980 || in>0x09FF) return 0;
    break;
  case SS_GURMUKHI:
    if (in<0x0A00 || in>0x0A7F) return 0;
    break;
  case SS_GUJARATI:
    if (in<0x0A80 || in>0x0AFF) return 0;
    break;
  case SS_ORIYA:
    if (in<0x0B00 || in>0x0B7F) return 0;
    break;
  case SS_TAMIL:
    if (in<0x0B80 || in>0x0BFF) return 0;
    break;
  case SS_TELUGU:
    if (in<0x0C00 || in>0x0C7F) return 0;
    break;
  case SS_KANNADA:
    if (in<0x0C80 || in>0x0CFF) return 0;
    break;
  case SS_MALAYALAM:
    if (in<0x0D00 || in>0x0D7F) return 0;
    break;
  case SS_SINHALA:
    if (in<0x0D80 || in>0x0DFF) return 0;
    break;
  case SS_THAI:
    if (in<0x0E00 || in>0x0E7F) return 0;
    break;
  case SS_LAO:
    if (in<0x0E80 || in>0x0EFF) return 0;
    break;
  case SS_TIBETAN:
    if (in<0x0F00 || in>0x0FFF) return 0;
    break;
  case SS_JAMO:
    if (in<0x1100 || in>0x11FF) return 0;
    break;
  }

  TTF_CMAP* cmap_table = (TTF_CMAP*) tables[SS_TB_CMAP];
  int num_tables = ntohs(cmap_table->numberOfEncodingTables);
  /* Go for it directly */
  bool uniconly = false;
  if (charEncoderTable != (unsigned int) num_tables)
  {
    TTF_CMAP_ENTRY* table_entry = 
             &(cmap_table->encodingTable[charEncoderTable]);

    int offset = ntohl(table_entry->offset);
    int format = ntohs(*((SD_USHORT*)((SD_BYTE*)cmap_table+offset)));
    SS_GlyphIndex gi=0;
    switch (format)
    {
    case 0:
      gi =  findGlyph0 ((TTF_CMAP_FMT0 *)((SD_BYTE *)cmap_table + offset), in);
      break;
    case 2:
      /* this has to have an encoder */
      if (fontencoding.size())
      {
        gi =  findGlyph2 ((TTF_CMAP_FMT2 *)((SD_BYTE *)cmap_table + offset), in);
      }
      break;
    case 4:
      gi =  findGlyph4 ((TTF_CMAP_FMT4 *)((SD_BYTE *)cmap_table + offset), in);
      break;
    case 8: /* TODO */
      break;
    case 10:
      break;
    case 12:
      gi =  findGlyph12 ((TTF_CMAP_FMT12 *)((SD_BYTE *)cmap_table + offset), in);
      break;
    default:
      break;
    }
    if (gi) return gi;
    /* look for unicode encoding only */
    uniconly = true;
  }
  //fprintf (stderr, "Second round\n");

  /* go through all tables */
  int platform = 0;
  int encoding_id = 0;
  for (int i=0; i < num_tables; i++)
  {
    TTF_CMAP_ENTRY* table_entry = &(cmap_table->encodingTable[i]);
    int offset = ntohl(table_entry->offset);
    int format = ntohs(*((SD_USHORT*)((SD_BYTE*)cmap_table+offset)));
    bool isok = true;
    if (uniconly)
    {
      platform = ntohs(table_entry->platformID);
      encoding_id = ntohs(table_entry->encodingID);
      isok = false;
      switch (platform)
      {
      case TT_PLAT_ID_MICROSOFT:
        switch (encoding_id)
        { 
        case TT_ENC_ID_MS_UNICODE:
        case TT_ENC_ID_MS_SURROGATES:
          isok = true; break;
        case TT_ENC_ID_MS_SYMBOL:
        case TT_ENC_ID_MS_SHIFT_JIS:
        case TT_ENC_ID_MS_BIG5:
        case TT_ENC_ID_MS_RPC:
        case TT_ENC_ID_MS_WANSUNG:
        case TT_ENC_ID_MS_JOHAB:
        default:
         break;
        }
        break;
      case TT_PLAT_ID_ISO:
        switch (encoding_id)
        { 
        case TT_ENC_ID_ISO_ASCII:
        case TT_ENC_ID_ISO_10646:
        case TT_ENC_ID_ISO_8859_1:
         isok = true; break;
        case TT_ENC_ID_ANY:
        default:
         break;
        }
        break;
      case TT_PLAT_ID_APPLE:
        switch (encoding_id)
        { 
        case TT_ENC_ID_APPLE_UNICODE_1_1:
        case TT_ENC_ID_APPLE_ISO_10646:
        case TT_ENC_ID_APPLE_UNICODE_2_0:
          isok = true; break;
        case TT_ENC_ID_APPLE_DEFAULT:
        default:
          break;
        }
        break;
      case TT_PLAT_ID_MACINTOSH:
        switch (encoding_id)
        { 
        case TT_ENC_ID_MAC_ROMAN:
          isok = true; break;
          /* a lot of other encodings missing */
        default:
          break;
        }
        break;
      default:
        break;
      }
    }
    if (!isok) continue;
    SS_GlyphIndex gi=0;
    switch (format)
    {
    case 0:/* TODO - SGC 8 bit*/
      gi =  findGlyph0 ((TTF_CMAP_FMT0 *)((SD_BYTE *)cmap_table + offset), in);
      break; 
    case 2:
      /* this has to have an encoder */
      if (fontencoding.size())
      {
        gi =  findGlyph2 ((TTF_CMAP_FMT2 *)((SD_BYTE *)cmap_table + offset), in);
      }
      break;
    case 4:
      gi =  findGlyph4 ((TTF_CMAP_FMT4 *)((SD_BYTE *)cmap_table + offset), in);
      break;
    case 8: /* TODO */
      break;
    case 10:
      break;
    case 12:
      gi =  findGlyph12 ((TTF_CMAP_FMT12 *)((SD_BYTE *)cmap_table + offset), in);
      break;
    default:
      break;
    }
/*
    if (uniconly && in > 0x1000 && format == 12 && gi)
    {
     fprintf (stderr, "platform = %d id=%d\n", platform, encoding_id);
    }
*/
    if (gi) return gi;
  }
  return 0;
}


Generated by  Doxygen 1.6.0   Back to index