CTLineGetBoundsWithOptions() what does the returned frame.origin.y value mean?

StackOverflow https://stackoverflow.com/questions/19709751

  •  02-07-2022
  •  | 
  •  

質問

When I do

CGRect lineBounds = CTLineGetBoundsWithOptions(lineRef, 0);

I get

(CGRect) lineBounds = origin=(x=0, y=-3.8560002) size=(width=181.31201, height=19.088001)

What information is the lineBounds.origin.y referring to? And why is it negative?

In contradiction to doing this where I get the excact same height and width - I don't get that -3.85 value.

double width = CTLineGetTypographicBounds(lineRef, &ascent, &descent, &leading);
double height = ascent + descent + leading;

So what does it tell me?

役に立ちましたか?

解決

Sadly there is no descent documentation on CTLineGetBoundsWithOptions function, but, as the header file states, this method returns

The bounds of the line as specified by the type and options, such that the coordinate origin is coincident with the line origin and the rect origin is at the bottom left. If the line is invalid this function will return CGRectNull.

You should obtain line origins using CTFrameGetLineOrigins and append corresponding origin to the obtained bounds origin.

Also, consider looking into CTLineBoundsOptions enumeration to filter unwanted elements

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top