InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IGlyphUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Pascal Rubini
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // ADOBE CONFIDENTIAL
24 //
25 //========================================================================================
26 
27 #ifndef __IGlyphUtils__
28 #define __IGlyphUtils__
29 
30 #include "IPMUnknown.h"
31 #include "IPMStream.h"
32 #include "Utils.h"
33 
34 #include "K2Vector.h"
35 #include "CTextEnum.h"
36 #include "TextID.h"
37 #include "ITextAttrGlyphForm.h"
38 #include "UnicodeClass.h"
39 
40 class IPMFont;
41 class ISelectionManager;
42 class IFontInstance;
43 class GlyphAccessData;
44 class WideString;
45 class AttributeBossList;
46 
53 {
54 public:
55  // constructor
56  typedef base_type data_type;
57  GlyphEntry(Text::GlyphID id = 0) :
58  fGlyphID(id),
59  fCachedUnicodeGlyphID(kMaxUInt32)
60  {}
61 
65  Text::GlyphID GetGlyphID() const { return fGlyphID; }
66 
70  void SetGlyphID(const Text::GlyphID glyphID) { fGlyphID = glyphID; }
71 
78 
85  bool16 GetOTFFeatureUnicodeCombo(IPMFont * font, GlyphAccessData & glyphAccessData) const;
86 
87 protected:
88  Text::GlyphID fGlyphID;
89 
90 protected:
91  UTF32TextChar fCachedUnicodeGlyphID;
92 };
93 
94 
98 {
99 public:
100  GlyphEntryUnicodeCompare(IPMFont* font) { fFont = font; }
101 
102  IPMFont* fFont;
103 
104  bool operator()(const GlyphEntry& glyph1, const GlyphEntry& glyph2)
105  {
106  UTF32TextChar g1 = glyph1.GetUnicodeGlyphID(fFont);
107  UTF32TextChar g2 = glyph2.GetUnicodeGlyphID(fFont);
108 
109  // One or both of glyphs doesn't have a unicode value. Put these glyphs at end.
110  if (g1 == 0 || g2 == 0)
111  {
112  if (g1 == 0 && g2 == 0)
113  return (glyph1.GetGlyphID() < glyph2.GetGlyphID()); // Two glyphs w/o unicode values, compare by glyph id
114  else if (g1 == 0)
115  return kFalse; // glyph1 has no unicode value but glyph2 does, consider glyph1 greater than glyph2
116  else
117  return kTrue; // glyph2 has no unicode value but glyph1 does, consider glyph1 less than glyph2
118  }
119  else if (g1 == g2)
120  {
121  return (glyph1.GetGlyphID() < glyph2.GetGlyphID()); // Two glyphs w/o unicode values, compare by glyph id
122  }
123 
124  // Comparing actual unicode values here
125  return (g1 < g2);
126  }
127 };
128 
132 {
133 public:
134  GlypyEntryCIDCompare(IPMFont* font) { fFont = font; }
135 
136  IPMFont* fFont;
137 
138  bool operator()(const GlyphEntry& glyph1, const GlyphEntry& glyph2)
139  {
140  return (glyph1.GetGlyphID() < glyph2.GetGlyphID()); // Compare by glyph id
141  }
142 };
143 
149 class GlyphSet: public K2Vector<GlyphEntry>
150 {
151 public:
155  int32 NumOfGlyphs() const
156  { return size(); }
157 
162  void AddGlyphEntry(bool checkUnique, Text::GlyphID altID)
163  {
164  if (checkUnique && GetGlyphIndex(altID) != -1)
165  return;
166  push_back(GlyphEntry(altID));
167  }
168 
177 
180  void Sort(IPMFont *font, GlyphSortOrder order)
181  {
182  if (order == kCIDOrder)
183  std::sort(begin(), end(), GlypyEntryCIDCompare(font));
184  else if (order == kUnicodeOrder)
185  std::sort(begin(), end(), GlyphEntryUnicodeCompare(font));
186  }
187 
192  Text::GlyphID GetGlyphID(int32 index) const
193  { return (*this)[index].GetGlyphID(); }
194 
200  UTF32TextChar GetUnicodeGlyphID(int32 index, IPMFont *font) const
201  { return (*this)[index].GetUnicodeGlyphID(font); }
202 
207  int32 GetGlyphIndex(Text::GlyphID id) const
208  {
209  for (int i = 0; i< NumOfGlyphs(); i++)
210  if (GetGlyphID(i) == id)
211  return i;
212  return -1;
213  }
214 
219  {
220  int32 glyphID(kInvalidGlyphID);
221  int32 j(0);
222  int32 numOfGlyphs(0);
223 
224  if (s->IsReading())
225  {
226  s->XferInt32(numOfGlyphs);
227  clear();
228  for (j = 0; j < numOfGlyphs; j++)
229  {
230  s->XferInt32(glyphID);
231  AddGlyphEntry(kFalse /*checkUnique*/, Text::GlyphID(glyphID));
232  }
233  }
234  else
235  {
236  numOfGlyphs = NumOfGlyphs();
237  s->XferInt32(numOfGlyphs);
238  for (j = 0; j < numOfGlyphs; j++)
239  {
240  glyphID = GetGlyphID(j);
241  s->XferInt32(glyphID);
242  }
243  }
244  }
245 
246 };
247 
250 typedef bool (* GlyphFilterProc) (const UTF32TextChar& c);
251 
258 
259 
263 class IGlyphUtils : public IPMUnknown
264 {
265 public:
266  enum { kDefaultIID = IID_IGLYPHUTILS };
267 
275  virtual UTF32TextChar GlyphToCharacter(IPMFont *font,Text::GlyphID id,UTF32TextChar* userArea = nil) = 0;
276 
283  virtual UTF32TextChar GetUnicodeForGlyphID(IPMFont *font, const Text::GlyphID& glyphID) const = 0;
284 
289  virtual PMString GetUnicodeName(const UTF32TextChar& c) = 0;
290 
300  virtual void InsertTheCharacter(ISelectionManager *selMgr, IPMFont *font, const GlyphEntry * baseGlyphEntry,
301  const GlyphEntry * alternateGlyphEntry, bool16 selectChar = kFalse, bool16 setFont = kFalse) = 0;
302 
313  virtual int32 GetSelectionGlyphSet(IPMFont *font, IFontInstance* fontInstance, const WideString& chars,
314  Text::GlyphID glyph, GlyphSet *glyphSet, GlyphSet::GlyphSortOrder sortOrder = GlyphSet::kNoOrder) = 0;
315 
325  virtual int32 GetGlyphListGlyphSet(IPMFont *font, IFontInstance* fontInstance, Text::GlyphID* glyphs,
326  int32 numGlyphs, GlyphSet * glyphSet, GlyphSet::GlyphSortOrder sortOrder = GlyphSet::kNoOrder) = 0;
327 
334  virtual bool16 GetGlyphHasAlternate(IPMFont *font, Text::GlyphID glyph, const char * tag = nil) = 0;
335 
342  virtual unsigned GetGlyphAlternateCount (IPMFont *font, Text::GlyphID glyph, const char * tag = nil) = 0;
343 
350  virtual int32 GetEntireFont(IPMFont *font, GlyphSet * glyphSet, GlyphSet::GlyphSortOrder sortOrder = GlyphSet::kNoOrder) = 0;
351 
361  virtual int32 GetFilteredGlyphs(IPMFont *font, GlyphSet * glyphSet, GlyphFilterProcList& includeFilterProcList, GlyphFilterProcList& excludeFilterProcList, GlyphSet::GlyphSortOrder sortOrder = GlyphSet::kNoOrder ) = 0;
362 
372  virtual int32 GetOTFFeatureGlyphSet(const char * tags, int32 numTags, IPMFont * font, GlyphSet * glyphSet, GlyphSet::GlyphSortOrder sortOrder = GlyphSet::kNoOrder) = 0;
373 
374 
385  virtual bool16 GetOTFFeature(IPMFont * font, IFontInstance * fontInstance, const GlyphEntry * baseGlyph, const GlyphEntry * alternate, char * tagBuffer/* 4 bytes */, int32 & choice) = 0;
386 
394  virtual int32 GetGlyphsForFeatureAccessInfo(const char * tags, int32 numTags, IPMFont * font,
395  GlyphSet * glyphSet) = 0;
396 
404  virtual int32 GetGlyphAccessInfo(Text::GlyphID glyphID, IPMFont * font,
405  GlyphAccessData * glyphAccessData) = 0;
406 
407 
419  virtual bool16 TestFeatureSubstitution(IFontInstance * fontInstance, const WideString& textString, char * tags, int32 * choices, int32 numFeatures, Text::GlyphID testGlyphID) = 0;
420 
431  virtual void GetOTFAttribute(char * tags, int32 choice, AttributeBossList * attrBossList, OpenTypeFeatureList& featureList, int32& form,
432  IFontInstance *fontInstance, const WideString& stringToApply, Text::GlyphID g) = 0;
433 
434 
439  virtual
440  bool
441  GlyphFormIsKnown (ITextAttrGlyphForm::GlyphForm feature) const
442  = 0;
443 
449  virtual
450  bool
451  IsGlyphFormFeature (int32 feature) const
452  = 0;
453 
458  virtual
459  bool
460  IsGlyphFormFeature (const char *feature) const
461  = 0;
462 
468  virtual
469  ITextAttrGlyphForm::GlyphForm
470  GlyphFormFromFeature (int32 feature) const
471  = 0;
472 
477  virtual
478  ITextAttrGlyphForm::GlyphForm
479  GlyphFormFromFeature (const char *feature) const
480  = 0;
481 
487  virtual
488  int32
489  GlyphFormToFeatureInt (ITextAttrGlyphForm::GlyphForm feature) const
490  = 0;
491 
496  virtual
497  const char *
498  GlyphFormToFeatureChars (ITextAttrGlyphForm::GlyphForm feature) const
499  = 0;
500 
505  virtual
506  const char *
507  GlyphFormDescriptiveString (ITextAttrGlyphForm::GlyphForm feature) const
508  = 0;
509 
510  virtual
511  ITextAttrGlyphForm::GlyphForm
512  GlyphFormIncrement (ITextAttrGlyphForm::GlyphForm &) const
513  = 0;
514 
515  virtual
516  ITextAttrGlyphForm::GlyphForm
517  GlyphFormDecrement (ITextAttrGlyphForm::GlyphForm &) const
518  = 0;
519 };
520 
521 #if IS_BIG_ENDIAN_ARCH
522 #define k_DLIG_CONSTANT 0x646C6967
523 #define k_HLIG_CONSTANT 0x686C6967
524 #define k_CASE_CONSTANT 0x63617365
525 #define k_C2SC_CONSTANT 0x63327363
526 #define k_SMCP_CONSTANT 0x736d6370
527 #define k_ONUM_CONSTANT 0x6f6e756d
528 #define k_PNUM_CONSTANT 0x706e756d
529 #define k_TNUM_CONSTANT 0x746e756d
530 #define k_LNUM_CONSTANT 0x6c6e756d
531 #define k_SUPS_CONSTANT 0x73757073
532 #define k_SINF_CONSTANT 0x73696e66
533 #define k_SUBS_CONSTANT 0x73756273
534 #define k_NUMR_CONSTANT 0x6e756d72
535 #define k_DNOM_CONSTANT 0x646e6f6d
536 #define k_SWSH_CONSTANT 0x73777368
537 #define k_CSWH_CONSTANT 0x63737768
538 #define k_TALT_CONSTANT 0x74616c74
539 #define k_CLIG_CONSTANT 0x636c6967
540 #define k_CALT_CONSTANT 0x63616c74
541 #define k_ORDN_CONSTANT 0x6f72646e
542 #define k_FRAC_CONSTANT 0x66726163
543 #define k_LIGA_CONSTANT 0x6c696761
544 #define k_HKNA_CONSTANT 0x686B6E61
545 #define k_VKNA_CONSTANT 0x766B6E61
546 #define k_ITAL_CONSTANT 0x6974616c
547 
548 #define k_TRAD_CONSTANT 0x74726164
549 #define k_EXPT_CONSTANT 0x65787074
550 #define k_JP78_CONSTANT 0x6a703738
551 #define k_JP83_CONSTANT 0x6a703833
552 #define k_HWID_CONSTANT 0x68776964
553 #define k_TWID_CONSTANT 0x74776964
554 #define k_QWID_CONSTANT 0x71776964
555 #define k_PWID_CONSTANT 0x70776964
556 #define k_FWID_CONSTANT 0x66776964
557 #define k_NLCK_CONSTANT 0x6E6C636B
558 #define k_JP04_CONSTANT 0x6a703034
559 #define k_JP90_CONSTANT 0x6a703930
560 
561 #define k_INIT_CONSTANT 0x696e6974
562 #define k_MEDI_CONSTANT 0x6d656469
563 #define k_FINA_CONSTANT 0x66696e61
564 #define k_ISOL_CONSTANT 0x69736f6c
565 
566 #else
567 
568 #define k_DLIG_CONSTANT 0x67696C64
569 #define k_HLIG_CONSTANT 0x67696C68
570 #define k_CASE_CONSTANT 0x65736163
571 #define k_C2SC_CONSTANT 0x63733263
572 #define k_SMCP_CONSTANT 0x70636d73
573 #define k_ONUM_CONSTANT 0x6d756e6f
574 #define k_PNUM_CONSTANT 0x6d756e70
575 #define k_TNUM_CONSTANT 0x6d756e74
576 #define k_LNUM_CONSTANT 0x6d756e6c
577 #define k_SUPS_CONSTANT 0x73707573
578 #define k_SINF_CONSTANT 0x666e6973
579 #define k_SUBS_CONSTANT 0x73627573
580 #define k_NUMR_CONSTANT 0x726d756e
581 #define k_DNOM_CONSTANT 0x6d6f6e64
582 #define k_SWSH_CONSTANT 0x68737773
583 #define k_CSWH_CONSTANT 0x68777363
584 #define k_TALT_CONSTANT 0x746c6174
585 #define k_CLIG_CONSTANT 0x67696c63
586 #define k_CALT_CONSTANT 0x746c6163
587 #define k_ORDN_CONSTANT 0x6e64726f
588 #define k_FRAC_CONSTANT 0x63617266
589 #define k_LIGA_CONSTANT 0x6167696c
590 #define k_HKNA_CONSTANT 0x616e6b68
591 #define k_VKNA_CONSTANT 0x616e6b76
592 #define k_ITAL_CONSTANT 0x6c617469
593 
594 #define k_TRAD_CONSTANT 0x64617274
595 #define k_EXPT_CONSTANT 0x74707865
596 #define k_JP78_CONSTANT 0x3837706a
597 #define k_JP83_CONSTANT 0x3338706a
598 #define k_HWID_CONSTANT 0x64697768
599 #define k_TWID_CONSTANT 0x64697774
600 #define k_QWID_CONSTANT 0x64697771
601 #define k_PWID_CONSTANT 0x64697770
602 #define k_FWID_CONSTANT 0x64697766
603 #define k_NLCK_CONSTANT 0x6B636C6E
604 #define k_JP04_CONSTANT 0x3430706a
605 #define k_JP90_CONSTANT 0x3039706a
606 
607 #define k_INIT_CONSTANT 0x74696e69
608 #define k_MEDI_CONSTANT 0x6964656d
609 #define k_FINA_CONSTANT 0x616e6966
610 #define k_ISOL_CONSTANT 0x6c6f7369
611 
612 #endif
613 
614 #endif
615  // __IGlyphUtils__
616