0

I want to display text with directwrite in a specified rectangle and with a specified font size, the text outside the rect should be cutted off.

By searching I found something about CreateTextLayout but it looked like it isn't possible to define the font size with it.

Only  the text in the red rectangle should be displayed

Thanks for answers.

Community
  • 1
  • 1
JCX
  • 1
  • 3

2 Answers2

0

It's not something DirectWrite is responsible for, unless you're using IDWriteBitmapRenderTarget. If you're using DrawText/DrawTextLayout from Direct2D you simply need to use D2D1_DRAW_TEXT_OPTIONS_CLIP option. If you are using DirectWrite bitmap target, it's enough to set target size to layout size, or to blit layout size portion to your destination context.

bunglehead
  • 1,104
  • 1
  • 14
  • 22
  • I was trying for cutting the text to a certain rectangle so that for example only half of a 'm' appears. Sorry for the imprecision of my question. – JCX Jun 24 '18 at 17:34
  • Then I don't understand what exactly are trying to achieve. Clipping option does not care if half of line will be visible. Do you want to show only first 3 lines for given width? – bunglehead Jun 24 '18 at 17:45
0

There is IDWriteTextFormat::SetTrimming(). When applied (with SetTrimming(&DWRITE_TRIMMING{DWRITE_TRIMMING_GRANULARITY_CHARACTER,0,0}, nullptr);), overflowing characters [glyph clusters?] and lines are omitted.

Pablo H
  • 609
  • 4
  • 22