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