@@ -274,69 +274,77 @@ - (void)drawLists:(id<EnrichedViewHost>)host
274274 [self glyphRangeForCharacterRange: [paragraph rangeValue ]
275275 actualCharacterRange: nullptr ];
276276
277- [self enumerateLineFragmentsForGlyphRange: paragraphGlyphRange
278- usingBlock: ^(CGRect rect, CGRect usedRect,
279- NSTextContainer *container,
280- NSRange lineGlyphRange,
281- BOOL *stop) {
282- NSUInteger charIdx =
283- [self characterIndexForGlyphAtIndex:
284- lineGlyphRange.location];
285- UIFont *font = [host.textView.textStorage
286- attribute: NSFontAttributeName
287- atIndex: charIdx
288- effectiveRange: nil ];
289- CGRect textUsedRect =
290- [self getTextAlignedUsedRect: usedRect
291- font: font];
292-
293- for (NSTextList *list in pStyle
294- .textLists ) {
295- NSString *markerFormat =
296- list.markerFormat ;
297-
298- if ([markerFormat
299- hasPrefix:
300- @" EnrichedAlignment" ]) {
301- continue ;
302- }
303-
304- if ([markerFormat
305- isEqualToString:
306- @" EnrichedOrderedList" ]) {
307- NSString *marker = [self
308- getDecimalMarkerForList: host
309- charIndex: charIdx];
310- [self drawDecimal: host
311- marker: marker
312- markerAttributes: markerAttributes
313- origin: origin
314- usedRect: usedRect
315- indent: indent];
316- } else if ([markerFormat
317- isEqualToString:
318- @" EnrichedUnordered"
319- @" Lis"
320- @" t" ]) {
321- [self drawBullet: host
322- origin: origin
323- usedRect: textUsedRect
324- indent: indent];
277+ [self
278+ enumerateLineFragmentsForGlyphRange: paragraphGlyphRange
279+ usingBlock: ^(CGRect rect, CGRect usedRect,
280+ NSTextContainer *container,
281+ NSRange lineGlyphRange,
282+ BOOL *stop) {
283+ NSUInteger charIdx =
284+ [self characterIndexForGlyphAtIndex:
285+ lineGlyphRange.location];
286+ UIFont *font = [host.textView.textStorage
287+ attribute: NSFontAttributeName
288+ atIndex: charIdx
289+ effectiveRange: nil ];
290+ CGRect textUsedRect =
291+ [self getTextAlignedUsedRect: usedRect
292+ font: font];
293+
294+ for (NSTextList *list in pStyle
295+ .textLists ) {
296+ NSString *markerFormat =
297+ list.markerFormat ;
298+
299+ if ([markerFormat
300+ hasPrefix:
301+ @" EnrichedAlignment" ]) {
302+ continue ;
303+ }
325304
326- } else if ([markerFormat
327- hasPrefix: @" EnrichedChe"
328- @" ckbox" ]) {
329- [self drawCheckbox: host
330- markerFormat: markerFormat
305+ if ([markerFormat
306+ isEqualToString:
307+ @" EnrichedOrderedList" ]) {
308+ CGPoint glyphLocation =
309+ [self locationForGlyphAtIndex:
310+ lineGlyphRange.location];
311+ CGFloat absoluteBaselineY =
312+ origin.y + rect.origin .y +
313+ glyphLocation.y ;
314+ NSString *marker = [self
315+ getDecimalMarkerForList: host
316+ charIndex: charIdx];
317+
318+ [self drawDecimal: host
319+ marker: marker
320+ markerAttributes: markerAttributes
331321 origin: origin
332- usedRect: textUsedRect
322+ baselineY: absoluteBaselineY
333323 indent: indent];
334- }
324+ } else if ([markerFormat
325+ isEqualToString:
326+ @" EnrichedUnordered"
327+ @" Lis"
328+ @" t" ]) {
329+ [self drawBullet: host
330+ origin: origin
331+ usedRect: textUsedRect
332+ indent: indent];
333+
334+ } else if ([markerFormat
335+ hasPrefix: @" EnrichedChe"
336+ @" ckbox" ]) {
337+ [self drawCheckbox: host
338+ markerFormat: markerFormat
339+ origin: origin
340+ usedRect: textUsedRect
341+ indent: indent];
335342 }
336- // only first line of a list gets its
337- // marker drawn
338- *stop = YES ;
339- }];
343+ }
344+ // only first line of a list gets its
345+ // marker drawn
346+ *stop = YES ;
347+ }];
340348 }
341349 }
342350}
@@ -439,13 +447,16 @@ - (void)drawDecimal:(id<EnrichedViewHost>)host
439447 marker : (NSString *)marker
440448 markerAttributes : (NSDictionary *)markerAttributes
441449 origin : (CGPoint)origin
442- usedRect : (CGRect) usedRect
450+ baselineY : (CGFloat) baselineY
443451 indent : (CGFloat)indent {
444452 CGFloat gapWidth = [host.config orderedListGapWidth ];
445453 CGSize markerSize = [marker sizeWithAttributes: markerAttributes];
446454 CGFloat markerX = origin.x + indent - gapWidth - markerSize.width / 2 ;
447- CGFloat centerY = CGRectGetMidY (usedRect) + origin.y ;
448- CGFloat markerY = centerY - markerSize.height / 2.0 ;
455+ UIFont *markerFont = markerAttributes[NSFontAttributeName ];
456+
457+ // drawAtPoint draws from the top-left bounding box of the string.
458+ // (baselineY - ascender) exactly pinpoints the top edge of the text
459+ CGFloat markerY = baselineY - markerFont.ascender ;
449460
450461 [marker drawAtPoint: CGPointMake (markerX, markerY)
451462 withAttributes: markerAttributes];
0 commit comments