InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SnpInsertGlyph Class Reference

Public Member Functions

 SnpInsertGlyph ()
 
virtual ~SnpInsertGlyph ()
 
ErrorCode InsertGlyph (InDesign::TextRange &textRange, IPMFont *font, const Text::GlyphID glyph)
 
IPMFontQueryFont (const InDesign::TextRange &textRange, PMString &fontFamilyName, PMString &fontStyleName)
 
const UTF32TextChar GlyphToCharacter (IPMFont *font, const Text::GlyphID glyph, UTF32TextChar *userAreaChar=nil)
 
const OpenTypeFeatureList GetOpenTypeFeatureList (IPMFont *font, const Text::GlyphID glyph)
 
ICommandCreateInsertAltGlyphCmd (const InDesign::TextRange &textRange, IPMFont *font, const OpenTypeFeatureList &featureList)
 
ICommandCreateInsertSpecialGlyphCmd (const InDesign::TextRange &textRange, IPMFont *font, const Text::GlyphID glyph)
 

Detailed Description

  • How to insert a glyph by its glyph ID (or character ID in a font).

This snippet allows you to insert a glyph by its glyph ID. What is special about this snippet is that it will adapt to glyphs with various special OpenType features, or even if the glyph is just a regular Unicode(TM) character. This snippet will try to find the Unicode character value for the specified glyph, and if it finds the Unicode value, then it will insert that character into the text model, along with necessary text attributes such as OpenType attributes. However, if the character does not have a Unicode character value, a placeholder character is inserted into the text model with an appropriate text attribute.

This snippet code contains code that is useful for situations where you have Unicode characters with alternate forms. This is common in OpenType fonts.

For example, the OpenType font Kozuma Mincho Pro - Regular contains 22 different glyph forms of the the NABE character (commonly used in the Japanese surname "Watanabe"). From the top row, left to right:

  • U+8FBA, ShiftJIS = 0x95D3, CID = 3621
  • U+908A, ShiftJIS = 0xE7B2, CID = 6929
  • U+9089, ShiftJIS = 0xE7B3, CID = 6930
  • U+9089, ShiftJIS = 0xE7B3, OpenType Tag = 'jp78', CID = 13407
  • U+9089, ShiftJIS = 0xE7B3, OpenType Tag = 'aalt', CID = 14235
  • U+9089, ShiftJIS = 0xE7B3, OpenType Tag = 'aalt', CID = 14236
  • ...
  • U+9089, ShiftJIS = 0xE7B3, OpenType Tag = 'aalt', CID = 14252

Note that many of these glyphs have the same Unicode character value. Therefore, if you simply inserted these characters by their Unicode character values, you may not get the glyph you want. One key difference between these glyphs is their CID (Character ID), or GlyphID. This snippet shows how to insert these different characters by their GlyphID.

NOTE: Due to a shortcoming in the IGlyphUtils interface, some glyphs that have multiple forms but with the same values (e.g. U+9089 with 'aalt' in the list above has 19 different forms), this sample will end up placing a placeholder character (either kTextChar_SpecialGlyph or kTextChar_NonRomanSpecialGlyph) into the text model with a kTextAttrSpecialGlyphBoss attribute.

See Also
Insert Glyph Panel in the application

Constructor & Destructor Documentation

SnpInsertGlyph::SnpInsertGlyph ()
inline

Constructor.

virtual SnpInsertGlyph::~SnpInsertGlyph ()
inlinevirtual

Destructor.

Member Function Documentation

ICommand * SnpInsertGlyph::CreateInsertAltGlyphCmd (const InDesign::TextRangetextRange,
IPMFontfont,
const OpenTypeFeatureListfeatureList 
)

Insert an alternate form of a glyph. This is used when the glyph has a corresponding Unicode codepoint.

Parameters
textRangeIN The text range where the special glyph is to be inserted.
fontIN The font associated with the glyph.
featureListIN The OpenType feature tags list to apply to the character
Returns
The command for inserting the special glyph. Nil if error.
ICommand * SnpInsertGlyph::CreateInsertSpecialGlyphCmd (const InDesign::TextRangetextRange,
IPMFontfont,
const Text::GlyphID glyph 
)

Create a command to insert a special form of a glyph. This is used when the glyph has no corresponding Unicode codepoint.

Parameters
textRangeIN The text range where the special glyph is to be inserted.
fontIN The font associated with the glyph.
glyphIN The glyph to insert. The font attribute kCharStringNames is automatically determined.
Returns
The command for inserting the special glyph. Nil if error.
const OpenTypeFeatureList SnpInsertGlyph::GetOpenTypeFeatureList (IPMFontfont,
const Text::GlyphID glyph 
)

Get the open type feature list applied to the glyph.

Parameters
fontIN The font associated with the glyph.
glyphIN The glyph to examine.
Returns
OpenTypeFeatureList for the glyph under question.
const UTF32TextChar SnpInsertGlyph::GlyphToCharacter (IPMFontfont,
const Text::GlyphID glyph,
UTF32TextCharuserAreaChar = nil 
)

Convert a glyph to a Unicode character. Also try to find if the glyph is in the Unicode private use area (PUA).

Parameters
fontIN The font associated with the glyph.
glyphIN The glyph to examine.
userAreaCharIN/OUT Pass in a non-nil UTF32TextChar in case the glyph is in the PUA. If it is in the PUA, the value will be something other than kTextChar_Null.
Returns
The Unicode character associated with the glyph. If there is no Unicode codepoint for the glyph, this will return kTextChar_Null.
ErrorCode SnpInsertGlyph::InsertGlyph (InDesign::TextRangetextRange,
IPMFontfont,
const Text::GlyphID glyph 
)

Insert a specific glyph by its glyph ID. Note that the Unicode character that corresponds to a specific glyph ID will vary with fonts.

This method will handle any of these cases:

  • (1) The glyph corresponds to a regular Unicode character that isn't an alternate form of any other Unicode character. In this case, the Unicode character is inserted directly.
  • (2) The glyph corresponds to a Unicode character, but is also an alternate form of another Unicode character. In this case, the AltGlyphAttrBoss is applied as an attribute.
  • (3) The glyph corresponds to a Unicode character in the Unicode private use area (PUA). (No alternates) In this case, the Unicode character is inserted directly.
  • (4) The glyph corresponds to a Unicode character in the Unicode private use area (PUA), and is also an alternate form of another Unicode character. In this case, the AltGlyphAttrBoss is applied as an attribute.
  • (5) The glyph doesn't have a corresponding Unicode codepoint. In this case, the TextAttrSpecialGlyphBoss is applied as an attribute.
Parameters
textRangeIN The text model and text range at which you want to insert the glyph.
fontIN The font associated with the glyph. Together with the glyph ID, you can identify a character.
glyphIN The glyph ID to insert. Note that glyph IDs are specific to fonts, so you must make sure the desired glyphID does exist in the font. Note that the glyph may not have an associated Unicode character code with it, and that a single Unicode characters may have multiple glyphs that correspond to it (e.g. alternate glyphs in OpenType fonts).
Returns
kSuccess on success, other ErrorCode otherwise.
IPMFont * SnpInsertGlyph::QueryFont (const InDesign::TextRangetextRange,
PMStringfontFamilyName,
PMStringfontStyleName 
)

Gets the IPMFont and the font names (family and style) at the given TextRange.

Parameters
textRangeIN The text range to examine.
fontFamilyNameOUT The family name of the font.
fontStyleNameOUT The style name of the font.
Returns
IPMFont that corresponds to the font. Nil if error.