Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How I could get the font UID from font name

Contributor ,
Oct 07, 2009 Oct 07, 2009

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

TOPICS
SDK
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 16, 2009 Oct 16, 2009
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines