Java Code Examples for java.awt.font.OpenType

The following are top voted examples for showing how to use java.awt.font.OpenType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: javify   File: OpenTypeFont.java   Source Code and License 6 votes vote down vote up
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;
  }
}
 
Example 2
Project: jvm-stm   File: OpenTypeFont.java   Source Code and License 6 votes vote down vote up
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;
  }
}
 
Example 3
Project: pdf-renderer-noawt   File: NativeFont.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Project: JamVM-PH   File: OpenTypeFont.java   Source Code and License 6 votes vote down vote up
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;
  }
}
 
Example 5
Project: classpath   File: OpenTypeFont.java   Source Code and License 6 votes vote down vote up
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;
  }
}
 
Example 6
Project: openjdk-jdk10   File: OpticalBoundsTagTest.java   Source Code and License 5 votes vote down vote up
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);
        }
    }
 
Example 7
Project: openjdk9   File: OpticalBoundsTagTest.java   Source Code and License 5 votes vote down vote up
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);
        }
    }
 
Example 8
Project: javify   File: OpenTypeFontFactory.java   Source Code and License 4 votes vote down vote up
/**
 * 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");
}
 
Example 9
Project: jvm-stm   File: OpenTypeFontFactory.java   Source Code and License 4 votes vote down vote up
/**
 * 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");
}
 
Example 10
Project: JamVM-PH   File: OpenTypeFontFactory.java   Source Code and License 4 votes vote down vote up
/**
 * 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");
}
 
Example 11
Project: classpath   File: OpenTypeFontFactory.java   Source Code and License 4 votes vote down vote up
/**
 * 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");
}
 
Example 12
Project: jftgl   File: FTGLDemo.java   Source Code and License 4 votes vote down vote up
/**
 * {@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();
}
 
Example 13
Project: javify   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 14
Project: javify   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 15
Project: jvm-stm   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 16
Project: jvm-stm   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 17
Project: JamVM-PH   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 18
Project: JamVM-PH   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 19
Project: classpath   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}
 
Example 20
Project: classpath   File: OpenTypeFont.java   Source Code and License 3 votes vote down vote up
/**
 * 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);
}