x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Composite Fonts, How to use?

With ue4 release 4.6 there came in composite fonts. Within the game content there can be created font objects containing multiple fonts. I only have found a description how to use font picker in a blueprint.

But how to use composite fonts in C++ to draw text on the HUD canvas?

E.g. I have created a composite font containing 4 fonts: alt text

Now using the font to draw a text on the screen.

 void AmyHUD::DrawHUD()
 {
   // Font'/Game/Fonts/CompositeVerdana.CompositeVerdana'
   UObject* obj_ptr = StaticLoadObject( UFont::StaticClass(), NULL,
                                  TEXT( "/Game/Fonts/CompositeVerdana" ) );
   UFont* font_ptr = Cast<UFont>( obj_ptr );
   this->DrawText( TEXT( "CompositeVerdana" ), FColor::White, 100.0f, 100.0f, font_ptr, 1 );
 }

The text "CompositeVerdana" appears on the screen with the first font, named "Normal". I assume that the first font will be used by default.

But how to address the the other fonts, named "Italic", "Bold", and "BoldItalic", and how to make use of them?

Is it intented to use composite font with C++, does it has any advantages for C++, or is it just for blueprint comfort, and better don't make use of composite fonts in C++.?

Product Version: UE 4.8
Tags:
more ▼

asked Jul 21 '15 at 10:56 AM in C++ Programming

avatar image

caribes
31 4 6 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

That's correct, Canvas will use the first font unless you specify otherwise.

Specifying which font to use for a HUD is a little cumbersome though, as AHUD doesn't have a function that takes a FCanvasTextItem, so you'll have to use the underlying Canvas directly... something like this:

 if (IsCanvasValid_WarnIfNot())
 {
     FCanvasTextItem TextItem(FVector2D(PosX, PosY), YourText, FSlateFontInfo(Font, FontSize,"Italic"), FLinearColor::White);
     Canvas->DrawItem(TextItem);
 }

It's fine to use composite fonts in C++, however they are best supported by Slate/UMG, rather than Canvas/HUD, and we recommend that UMG or Slate be used for any non-debug UIs.

more ▼

answered Jul 21 '15 at 11:09 AM

avatar image

Jamie Dale STAFF
7.5k 177 67 307

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question