Skip to main content
Inspiring
October 7, 2009
Question

How I could get the font UID from font name

  • October 7, 2009
  • 1 reply
  • 1738 views

HI All,

I have a text frame having some text and I need to apply following on text

1. Font name

2. Font style

3. Font size

Suppose I have font name "Arial"  font style Bold and font size 14

How I could apply all the three attribute to the text

I am able to set font style and font size.

On looking into the SDK I have found that font family name is stored in the form of UID on kTextAttrFontUIDBoss

So I need to get the font UID from font name.

Regards,

Alam

This topic has been closed for replies.

1 reply

Participating Frequently
October 16, 2009

The code below is not exactly what you want, but might serve as inspiration...

do {
InterfacePtr<IDocument> doc(Utils<ILayoutUIUtils>()->GetFrontDocument(),UseDefaultIID());
if (doc == nil) {
  break;
}
IDataBase *db = ::GetDataBase(doc);
InterfacePtr<IStyleGroupManager> iParaStyleNameTable(doc->GetDocWorkSpace(), IID_IPARASTYLEGROUPMANAGER);
if (iParaStyleNameTable == nil) {
  break;
}

UIDList psUIDList(db);
iParaStyleNameTable->GetRootHierarchy()->GetDescendents(&psUIDList,IID_ISTYLEINFO);
int32 psCount = psUIDList.Length();

while (psCount-- > 0) {
  UID styleUID = psUIDList[psCount];
  int32 mFontFamilyIndex;  //
  int32 mFontStyleIndex;  //

  InterfacePtr<ITextAttributes> iTextAttributes(psUIDList.GetDataBase (), styleUID, UseDefaultIID());
  if (iTextAttributes == nil) {
   break;
  }
  int32 i = iTextAttributes->CountBosses();
  while (i-- > 0) {
   ClassID c = iTextAttributes->GetClassN(i);

   switch (c.Get()) {
   case kTextAttrFontUIDBoss:
    mFontFamilyIndex = i;
    break;
   case kTextAttrFontStyleBoss:
    mFontStyleIndex = i;
    InterfacePtr<ITextAttrUID> iFont((ITextAttrUID *)iTextAttributes->QueryBossN(mFontFamilyIndex, IID_ITEXTATTRUID));
    if (iFont == nil) {
     break;
    }
    InterfacePtr<ITextAttrFont> iFontStyle((ITextAttrFont *)iTextAttributes->QueryBossN(mFontStyleIndex, IID_ITEXTATTRFONT));
    if (iFont == nil) {
     break;
    }
    InterfacePtr<IFontFamily> font(db, iFont->Get(), IID_IFONTFAMILY);
    if (font == nil) {
     break;
    }
    InterfacePtr<IPMFont> face(font->QueryFace(iFontStyle->GetFontName()));

    if (face != nil) {
     PMString fontname;
     face->AppendFontName(fontname);
    }
    break;
   }
  }
}
} while (kFalse);