Java 类java.awt.font.OpenType 实例源码

项目:javify    文件:OpenTypeFont.java   
private CharGlyphMap getCharGlyphMap()
{
  if (cmap != null)
    return cmap;

  synchronized (this)
  {
    if (cmap == null)
    {
      int index = getTableIndex(OpenType.TAG_CMAP);
      int start = tableStart[index];
      buf.limit(start + tableLength[index]).position(start);
      cmap = CharGlyphMap.forTable(buf);
    }
    return cmap;
  }
}
项目:jvm-stm    文件:OpenTypeFont.java   
private CharGlyphMap getCharGlyphMap()
{
  if (cmap != null)
    return cmap;

  synchronized (this)
  {
    if (cmap == null)
    {
      int index = getTableIndex(OpenType.TAG_CMAP);
      int start = tableStart[index];
      buf.limit(start + tableLength[index]).position(start);
      cmap = CharGlyphMap.forTable(buf);
    }
    return cmap;
  }
}
项目:pdf-renderer-noawt    文件:NativeFont.java   
/**
 * Set the font
 *
 * @param f the font to use
 */
protected void setFont (Font f) {
    this.f = f;

    // if it's an OpenType font, parse the relevant tables to get
    // glyph name to code mappings
    if (f instanceof OpenType) {
        OpenType ot = (OpenType) f;

        byte[] cmapData = ot.getFontTable (OpenType.TAG_CMAP);
        byte[] postData = ot.getFontTable (OpenType.TAG_POST);

        TrueTypeFont ttf = new TrueTypeFont (0x10000);

        cmapTable =
        (CmapTable) TrueTypeTable.createTable (ttf, "cmap",
                ByteBuffer.wrap (cmapData));
        ttf.addTable ("cmap", cmapTable);

        postTable =
        (PostTable) TrueTypeTable.createTable (ttf, "post",
                ByteBuffer.wrap (postData));
        ttf.addTable ("post", postTable);
    }
}
项目:JamVM-PH    文件:OpenTypeFont.java   
private CharGlyphMap getCharGlyphMap()
{
  if (cmap != null)
    return cmap;

  synchronized (this)
  {
    if (cmap == null)
    {
      int index = getTableIndex(OpenType.TAG_CMAP);
      int start = tableStart[index];
      buf.limit(start + tableLength[index]).position(start);
      cmap = CharGlyphMap.forTable(buf);
    }
    return cmap;
  }
}
项目:classpath    文件:OpenTypeFont.java   
private CharGlyphMap getCharGlyphMap()
{
  if (cmap != null)
    return cmap;

  synchronized (this)
  {
    if (cmap == null)
    {
      int index = getTableIndex(OpenType.TAG_CMAP);
      int start = tableStart[index];
      buf.limit(start + tableLength[index]).position(start);
      cmap = CharGlyphMap.forTable(buf);
    }
    return cmap;
  }
}
项目:openjdk-jdk10    文件:OpticalBoundsTagTest.java   
public static void main(String[] a) throws Exception {

        int tag_opbd = java.awt.font.OpenType.TAG_OPBD;
        if (tag_opbd == java.awt.font.OpenType.TAG_MORT) {
            System.out.println("Test failed: TAG_OPBD:" + tag_opbd);
            throw new RuntimeException("TAG_OPBD same as TAG_MORT");
        } else {
            System.out.println("Test passed: TAG_OPBD: " + tag_opbd);
        }
    }
项目:openjdk9    文件:OpticalBoundsTagTest.java   
public static void main(String[] a) throws Exception {

        int tag_opbd = java.awt.font.OpenType.TAG_OPBD;
        if (tag_opbd == java.awt.font.OpenType.TAG_MORT) {
            System.out.println("Test failed: TAG_OPBD:" + tag_opbd);
            throw new RuntimeException("TAG_OPBD same as TAG_MORT");
        } else {
            System.out.println("Test passed: TAG_OPBD: " + tag_opbd);
        }
    }
项目:javify    文件:OpenTypeFontFactory.java   
/**
 * Creates FontDelegate objects for the fonts in the specified
 * buffer.  The following font formats are currently recognized:
 *
 * <p><ul>
 * <li>OpenType (*.otf);</li>
 * <li>TrueType (*.ttf);</li>
 * <li>TrueType Collections (*.ttc);</li>
 * <li>Apple MacOS X data-fork font (*.dfont).</li></ul>
 *
 * <p>Some formats may contain more than a single font, for example
 * *.ttc and *.dfont files. This is the reason why this function
 * returns an array.
 *
 * <p>The implementation reads data from the buffer only when
 * needed. Therefore, it greatly increases efficiency if
 * <code>buf</code> has been obtained through mapping a file into
 * the virtual address space.
 *
 * @throws FontFormatException if the font data is not in one of the
 * known formats.
 */
public static FontDelegate[] createFonts(ByteBuffer buf)
  throws FontFormatException
{
  OpenTypeFont[] fonts;
  int version;

  version = buf.getInt(0);
  switch (version)
  {
  case 0x00010000:            // Microsoft Windows TrueType
  case OpenType.TAG_TYP1:     // Apple MacOS PostScript ('typ1')
  case OpenTypeFont.TAG_SFNT: // Apple MacOS TrueType ('sfnt')
  case OpenTypeFont.TAG_TRUE: // Apple MacOS TrueType ('true')
  case OpenTypeFont.TAG_OTTO: // OpenType
    return new OpenTypeFont[] { new OpenTypeFont(buf, 0) };
  }


  /* TrueType Collection, see "TrueType Collections" in
   * http://partners.adobe.com/asn/tech/type/opentype/otff.html
   */
  if (version == OpenTypeFont.TAG_TTCF)
  {
    // This code has never been tested.
    fonts = new OpenTypeFont[buf.getInt(8)];
    for (int i = 0; i < fonts.length; i++)
      fonts[i] = new OpenTypeFont(buf, buf.getInt(16 + 4 * i));
    return fonts;
  }


  /* The MacOS X .dfont format is a Macintosh resource fork in
   * a normal file, contaning one or several 'sfnt' resources.
   * Unfortunately, MacOS resource forks have no magic code
   * that could be used for identification. Instead, we just try
   * to extract at least one 'sfnt'.
   */
  try
  {
    MacResourceFork fork = new MacResourceFork(buf);
    MacResourceFork.Resource[] rsrc;

    rsrc = fork.getResources(OpenTypeFont.TAG_SFNT);
    fonts = new OpenTypeFont[rsrc.length];
    for (int i = 0; i < fonts.length; i++)
      fonts[i] = new OpenTypeFont(rsrc[i].getContent(), 0);

    return fonts;
  }
  catch (Exception ex)
  {
  }

  throw new FontFormatException("not in OpenType or TrueType format");
}
项目:jvm-stm    文件:OpenTypeFontFactory.java   
/**
 * Creates FontDelegate objects for the fonts in the specified
 * buffer.  The following font formats are currently recognized:
 *
 * <p><ul>
 * <li>OpenType (*.otf);</li>
 * <li>TrueType (*.ttf);</li>
 * <li>TrueType Collections (*.ttc);</li>
 * <li>Apple MacOS X data-fork font (*.dfont).</li></ul>
 *
 * <p>Some formats may contain more than a single font, for example
 * *.ttc and *.dfont files. This is the reason why this function
 * returns an array.
 *
 * <p>The implementation reads data from the buffer only when
 * needed. Therefore, it greatly increases efficiency if
 * <code>buf</code> has been obtained through mapping a file into
 * the virtual address space.
 *
 * @throws FontFormatException if the font data is not in one of the
 * known formats.
 */
public static FontDelegate[] createFonts(ByteBuffer buf)
  throws FontFormatException
{
  OpenTypeFont[] fonts;
  int version;

  version = buf.getInt(0);
  switch (version)
  {
  case 0x00010000:            // Microsoft Windows TrueType
  case OpenType.TAG_TYP1:     // Apple MacOS PostScript ('typ1')
  case OpenTypeFont.TAG_SFNT: // Apple MacOS TrueType ('sfnt')
  case OpenTypeFont.TAG_TRUE: // Apple MacOS TrueType ('true')
  case OpenTypeFont.TAG_OTTO: // OpenType
    return new OpenTypeFont[] { new OpenTypeFont(buf, 0) };
  }


  /* TrueType Collection, see "TrueType Collections" in
   * http://partners.adobe.com/asn/tech/type/opentype/otff.html
   */
  if (version == OpenTypeFont.TAG_TTCF)
  {
    // This code has never been tested.
    fonts = new OpenTypeFont[buf.getInt(8)];
    for (int i = 0; i < fonts.length; i++)
      fonts[i] = new OpenTypeFont(buf, buf.getInt(16 + 4 * i));
    return fonts;
  }


  /* The MacOS X .dfont format is a Macintosh resource fork in
   * a normal file, contaning one or several 'sfnt' resources.
   * Unfortunately, MacOS resource forks have no magic code
   * that could be used for identification. Instead, we just try
   * to extract at least one 'sfnt'.
   */
  try
  {
    MacResourceFork fork = new MacResourceFork(buf);
    MacResourceFork.Resource[] rsrc;

    rsrc = fork.getResources(OpenTypeFont.TAG_SFNT);
    fonts = new OpenTypeFont[rsrc.length];
    for (int i = 0; i < fonts.length; i++)      
      fonts[i] = new OpenTypeFont(rsrc[i].getContent(), 0);

    return fonts;
  }
  catch (Exception ex)
  {
  }

  throw new FontFormatException("not in OpenType or TrueType format");
}
项目:JamVM-PH    文件:OpenTypeFontFactory.java   
/**
 * Creates FontDelegate objects for the fonts in the specified
 * buffer.  The following font formats are currently recognized:
 *
 * <p><ul>
 * <li>OpenType (*.otf);</li>
 * <li>TrueType (*.ttf);</li>
 * <li>TrueType Collections (*.ttc);</li>
 * <li>Apple MacOS X data-fork font (*.dfont).</li></ul>
 *
 * <p>Some formats may contain more than a single font, for example
 * *.ttc and *.dfont files. This is the reason why this function
 * returns an array.
 *
 * <p>The implementation reads data from the buffer only when
 * needed. Therefore, it greatly increases efficiency if
 * <code>buf</code> has been obtained through mapping a file into
 * the virtual address space.
 *
 * @throws FontFormatException if the font data is not in one of the
 * known formats.
 */
public static FontDelegate[] createFonts(ByteBuffer buf)
  throws FontFormatException
{
  OpenTypeFont[] fonts;
  int version;

  version = buf.getInt(0);
  switch (version)
  {
  case 0x00010000:            // Microsoft Windows TrueType
  case OpenType.TAG_TYP1:     // Apple MacOS PostScript ('typ1')
  case OpenTypeFont.TAG_SFNT: // Apple MacOS TrueType ('sfnt')
  case OpenTypeFont.TAG_TRUE: // Apple MacOS TrueType ('true')
  case OpenTypeFont.TAG_OTTO: // OpenType
    return new OpenTypeFont[] { new OpenTypeFont(buf, 0) };
  }


  /* TrueType Collection, see "TrueType Collections" in
   * http://partners.adobe.com/asn/tech/type/opentype/otff.html
   */
  if (version == OpenTypeFont.TAG_TTCF)
  {
    // This code has never been tested.
    fonts = new OpenTypeFont[buf.getInt(8)];
    for (int i = 0; i < fonts.length; i++)
      fonts[i] = new OpenTypeFont(buf, buf.getInt(16 + 4 * i));
    return fonts;
  }


  /* The MacOS X .dfont format is a Macintosh resource fork in
   * a normal file, contaning one or several 'sfnt' resources.
   * Unfortunately, MacOS resource forks have no magic code
   * that could be used for identification. Instead, we just try
   * to extract at least one 'sfnt'.
   */
  try
  {
    MacResourceFork fork = new MacResourceFork(buf);
    MacResourceFork.Resource[] rsrc;

    rsrc = fork.getResources(OpenTypeFont.TAG_SFNT);
    fonts = new OpenTypeFont[rsrc.length];
    for (int i = 0; i < fonts.length; i++)      
      fonts[i] = new OpenTypeFont(rsrc[i].getContent(), 0);

    return fonts;
  }
  catch (Exception ex)
  {
  }

  throw new FontFormatException("not in OpenType or TrueType format");
}
项目:classpath    文件:OpenTypeFontFactory.java   
/**
 * Creates FontDelegate objects for the fonts in the specified
 * buffer.  The following font formats are currently recognized:
 *
 * <p><ul>
 * <li>OpenType (*.otf);</li>
 * <li>TrueType (*.ttf);</li>
 * <li>TrueType Collections (*.ttc);</li>
 * <li>Apple MacOS X data-fork font (*.dfont).</li></ul>
 *
 * <p>Some formats may contain more than a single font, for example
 * *.ttc and *.dfont files. This is the reason why this function
 * returns an array.
 *
 * <p>The implementation reads data from the buffer only when
 * needed. Therefore, it greatly increases efficiency if
 * <code>buf</code> has been obtained through mapping a file into
 * the virtual address space.
 *
 * @throws FontFormatException if the font data is not in one of the
 * known formats.
 */
public static FontDelegate[] createFonts(ByteBuffer buf)
  throws FontFormatException
{
  OpenTypeFont[] fonts;
  int version;

  version = buf.getInt(0);
  switch (version)
  {
  case 0x00010000:            // Microsoft Windows TrueType
  case OpenType.TAG_TYP1:     // Apple MacOS PostScript ('typ1')
  case OpenTypeFont.TAG_SFNT: // Apple MacOS TrueType ('sfnt')
  case OpenTypeFont.TAG_TRUE: // Apple MacOS TrueType ('true')
  case OpenTypeFont.TAG_OTTO: // OpenType
    return new OpenTypeFont[] { new OpenTypeFont(buf, 0) };
  }


  /* TrueType Collection, see "TrueType Collections" in
   * http://partners.adobe.com/asn/tech/type/opentype/otff.html
   */
  if (version == OpenTypeFont.TAG_TTCF)
  {
    // This code has never been tested.
    fonts = new OpenTypeFont[buf.getInt(8)];
    for (int i = 0; i < fonts.length; i++)
      fonts[i] = new OpenTypeFont(buf, buf.getInt(16 + 4 * i));
    return fonts;
  }


  /* The MacOS X .dfont format is a Macintosh resource fork in
   * a normal file, contaning one or several 'sfnt' resources.
   * Unfortunately, MacOS resource forks have no magic code
   * that could be used for identification. Instead, we just try
   * to extract at least one 'sfnt'.
   */
  try
  {
    MacResourceFork fork = new MacResourceFork(buf);
    MacResourceFork.Resource[] rsrc;

    rsrc = fork.getResources(OpenTypeFont.TAG_SFNT);
    fonts = new OpenTypeFont[rsrc.length];
    for (int i = 0; i < fonts.length; i++)
      fonts[i] = new OpenTypeFont(rsrc[i].getContent(), 0);

    return fonts;
  }
  catch (Exception ex)
  {
  }

  throw new FontFormatException("not in OpenType or TrueType format");
}
项目:jftgl    文件:FTGLDemo.java   
/**
 * {@inheritDoc}
 */
public String toString()
{
    StringBuffer sb = new StringBuffer();
    switch (this.mode)
    {
        case EDITING:
            sb.append("\tMode: Edit Mode\n");
            break;
        case INTERACTIVE:
            sb.append("\tMode: Interactive Mode\n");
            break;
    }
    sb.append("\tType: ");
    switch (this.current_font)
    {
        case FTGL_BITMAP:
            sb.append("Bitmap Font\n");
            break;
        case FTGL_PIXMAP:
            sb.append("Pixmap Font\n");
            break;
        case FTGL_OUTLINE:
            sb.append("Outline Font\n");
            break;
        case FTGL_POLYGON:
            sb.append("Polygon Font\n");
            break;
        case FTGL_EXTRUDE:
            sb.append("Extruded Font\n");
            break;
        case FTGL_TEXTURE:
            sb.append("Texture Font\n");
            break;
    }

    if (this.font instanceof OpenType) sb.append(" (OpenType) ");

    sb.append("\tFontfile: ");
    sb.append(this.font.getFontName());
    sb.append("\n");
    return sb.toString();
}
项目:javify    文件:OpenTypeFont.java   
/**
 * Extracts a String from the font&#x2019;s name table.
 *
 * @param name the numeric TrueType or OpenType name ID.
 *
 * @param locale the locale for which names shall be localized, or
 * <code>null</code> if the locale does mot matter because the name
 * is known to be language-independent (for example, because it is
 * the PostScript name).
 */
private String getName(int name, Locale locale)
{
  if (nameTable == null)
    nameTable = getFontTable(OpenType.TAG_NAME);
  return NameDecoder.getName(nameTable, name, locale);
}
项目:javify    文件:OpenTypeFont.java   
/**
 * Returns a name for the specified glyph. This is useful for
 * generating PostScript or PDF files that embed some glyphs of a
 * font.
 *
 * <p><b>Names are not unique:</b> Under some rare circumstances,
 * the same name can be returned for different glyphs. It is
 * therefore recommended that printer drivers check whether the same
 * name has already been returned for antoher glyph, and make the
 * name unique by adding the string ".alt" followed by the glyph
 * index.</p>
 *
 * <p>This situation would occur for an OpenType or TrueType font
 * that has a <code>post</code> table of format 3 and provides a
 * mapping from glyph IDs to Unicode sequences through a
 * <code>Zapf</code> table. If the same sequence of Unicode
 * codepoints leads to different glyphs (depending on contextual
 * position, for example, or on typographic sophistication level),
 * the same name would get synthesized for those glyphs.
 *
 * @param glyphIndex the glyph whose name the caller wants to
 * retrieve.
 */
public synchronized String getGlyphName(int glyphIndex)
{
  if (glyphNamer == null)
    glyphNamer = GlyphNamer.forTables(numGlyphs,
                                      getFontTable(OpenType.TAG_POST),
                                      getFontTable(TAG_ZAPF));

  return glyphNamer.getGlyphName(glyphIndex);
}
项目:jvm-stm    文件:OpenTypeFont.java   
/**
 * Extracts a String from the font&#x2019;s name table.
 *
 * @param name the numeric TrueType or OpenType name ID.
 *
 * @param locale the locale for which names shall be localized, or
 * <code>null</code> if the locale does mot matter because the name
 * is known to be language-independent (for example, because it is
 * the PostScript name).
 */
private String getName(int name, Locale locale)
{
  if (nameTable == null)
    nameTable = getFontTable(OpenType.TAG_NAME);
  return NameDecoder.getName(nameTable, name, locale);
}
项目:jvm-stm    文件:OpenTypeFont.java   
/**
 * Returns a name for the specified glyph. This is useful for
 * generating PostScript or PDF files that embed some glyphs of a
 * font.
 *
 * <p><b>Names are not unique:</b> Under some rare circumstances,
 * the same name can be returned for different glyphs. It is
 * therefore recommended that printer drivers check whether the same
 * name has already been returned for antoher glyph, and make the
 * name unique by adding the string ".alt" followed by the glyph
 * index.</p>
 *
 * <p>This situation would occur for an OpenType or TrueType font
 * that has a <code>post</code> table of format 3 and provides a
 * mapping from glyph IDs to Unicode sequences through a
 * <code>Zapf</code> table. If the same sequence of Unicode
 * codepoints leads to different glyphs (depending on contextual
 * position, for example, or on typographic sophistication level),
 * the same name would get synthesized for those glyphs.
 *
 * @param glyphIndex the glyph whose name the caller wants to
 * retrieve.
 */
public synchronized String getGlyphName(int glyphIndex)
{
  if (glyphNamer == null)
    glyphNamer = GlyphNamer.forTables(numGlyphs,
                                      getFontTable(OpenType.TAG_POST),
                                      getFontTable(TAG_ZAPF));

  return glyphNamer.getGlyphName(glyphIndex);
}
项目:JamVM-PH    文件:OpenTypeFont.java   
/**
 * Extracts a String from the font&#x2019;s name table.
 *
 * @param name the numeric TrueType or OpenType name ID.
 *
 * @param locale the locale for which names shall be localized, or
 * <code>null</code> if the locale does mot matter because the name
 * is known to be language-independent (for example, because it is
 * the PostScript name).
 */
private String getName(int name, Locale locale)
{
  if (nameTable == null)
    nameTable = getFontTable(OpenType.TAG_NAME);
  return NameDecoder.getName(nameTable, name, locale);
}
项目:JamVM-PH    文件:OpenTypeFont.java   
/**
 * Returns a name for the specified glyph. This is useful for
 * generating PostScript or PDF files that embed some glyphs of a
 * font.
 *
 * <p><b>Names are not unique:</b> Under some rare circumstances,
 * the same name can be returned for different glyphs. It is
 * therefore recommended that printer drivers check whether the same
 * name has already been returned for antoher glyph, and make the
 * name unique by adding the string ".alt" followed by the glyph
 * index.</p>
 *
 * <p>This situation would occur for an OpenType or TrueType font
 * that has a <code>post</code> table of format 3 and provides a
 * mapping from glyph IDs to Unicode sequences through a
 * <code>Zapf</code> table. If the same sequence of Unicode
 * codepoints leads to different glyphs (depending on contextual
 * position, for example, or on typographic sophistication level),
 * the same name would get synthesized for those glyphs.
 *
 * @param glyphIndex the glyph whose name the caller wants to
 * retrieve.
 */
public synchronized String getGlyphName(int glyphIndex)
{
  if (glyphNamer == null)
    glyphNamer = GlyphNamer.forTables(numGlyphs,
                                      getFontTable(OpenType.TAG_POST),
                                      getFontTable(TAG_ZAPF));

  return glyphNamer.getGlyphName(glyphIndex);
}
项目:classpath    文件:OpenTypeFont.java   
/**
 * Extracts a String from the font&#x2019;s name table.
 *
 * @param name the numeric TrueType or OpenType name ID.
 *
 * @param locale the locale for which names shall be localized, or
 * <code>null</code> if the locale does mot matter because the name
 * is known to be language-independent (for example, because it is
 * the PostScript name).
 */
private String getName(int name, Locale locale)
{
  if (nameTable == null)
    nameTable = getFontTable(OpenType.TAG_NAME);
  return NameDecoder.getName(nameTable, name, locale);
}
项目:classpath    文件:OpenTypeFont.java   
/**
 * Returns a name for the specified glyph. This is useful for
 * generating PostScript or PDF files that embed some glyphs of a
 * font.
 *
 * <p><b>Names are not unique:</b> Under some rare circumstances,
 * the same name can be returned for different glyphs. It is
 * therefore recommended that printer drivers check whether the same
 * name has already been returned for antoher glyph, and make the
 * name unique by adding the string ".alt" followed by the glyph
 * index.</p>
 *
 * <p>This situation would occur for an OpenType or TrueType font
 * that has a <code>post</code> table of format 3 and provides a
 * mapping from glyph IDs to Unicode sequences through a
 * <code>Zapf</code> table. If the same sequence of Unicode
 * codepoints leads to different glyphs (depending on contextual
 * position, for example, or on typographic sophistication level),
 * the same name would get synthesized for those glyphs.
 *
 * @param glyphIndex the glyph whose name the caller wants to
 * retrieve.
 */
public synchronized String getGlyphName(int glyphIndex)
{
  if (glyphNamer == null)
    glyphNamer = GlyphNamer.forTables(numGlyphs,
                                      getFontTable(OpenType.TAG_POST),
                                      getFontTable(TAG_ZAPF));

  return glyphNamer.getGlyphName(glyphIndex);
}