forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSAttributedString+ASText.h
More file actions
1375 lines (1124 loc) · 54.8 KB
/
Copy pathNSAttributedString+ASText.h
File metadata and controls
1375 lines (1124 loc) · 54.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// NSAttributedString+ASText.h
// Texture
//
// Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <UIKit/UIKit.h>
#import <CoreText/CoreText.h>
#import <AsyncDisplayKit/ASTextAttribute.h>
NS_ASSUME_NONNULL_BEGIN
/**
Get pre-defined attributes from attributed string.
All properties defined in UIKit, CoreText and ASText are included.
*/
@interface NSAttributedString (ASText)
#pragma mark - Retrieving character attribute information
///=============================================================================
/// @name Retrieving character attribute information
///=============================================================================
/**
Returns the attributes at first charactor.
*/
@property (nullable, nonatomic, copy, readonly) NSDictionary<NSString *, id> *as_attributes;
/**
Returns the attributes for the character at a given index.
@discussion Raises an `NSRangeException` if index lies beyond the end of the
receiver's characters.
@param index The index for which to return attributes.
This value must lie within the bounds of the receiver.
@return The attributes for the character at index.
*/
- (nullable NSDictionary<NSString *, id> *)as_attributesAtIndex:(NSUInteger)index;
/**
Returns the value for an attribute with a given name of the character at a given index.
@discussion Raises an `NSRangeException` if index lies beyond the end of the
receiver's characters.
@param attributeName The name of an attribute.
@param index The index for which to return attributes.
This value must not exceed the bounds of the receiver.
@return The value for the attribute named `attributeName` of the character at
index `index`, or nil if there is no such attribute.
*/
- (nullable id)as_attribute:(NSString *)attributeName atIndex:(NSUInteger)index;
#pragma mark - Get character attribute as property
///=============================================================================
/// @name Get character attribute as property
///=============================================================================
/**
The font of the text. (read-only)
@discussion Default is Helvetica (Neue) 12.
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) UIFont *as_font;
- (nullable UIFont *)as_fontAtIndex:(NSUInteger)index;
/**
A kerning adjustment. (read-only)
@discussion Default is standard kerning. The kerning attribute indicate how many
points the following character should be shifted from its default offset as
defined by the current character's font in points; a positive kern indicates a
shift farther along and a negative kern indicates a shift closer to the current
character. If this attribute is not present, standard kerning will be used.
If this attribute is set to 0.0, no kerning will be done at all.
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) NSNumber *as_kern;
- (nullable NSNumber *)as_kernAtIndex:(NSUInteger)index;
/**
The foreground color. (read-only)
@discussion Default is Black.
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) UIColor *as_color;
- (nullable UIColor *)as_colorAtIndex:(NSUInteger)index;
/**
The background color. (read-only)
@discussion Default is nil (or no background).
@discussion Get this property returns the first character's attribute.
@since UIKit:6.0
*/
@property (nullable, nonatomic, readonly) UIColor *as_backgroundColor;
- (nullable UIColor *)as_backgroundColorAtIndex:(NSUInteger)index;
/**
The stroke width. (read-only)
@discussion Default value is 0.0 (no stroke). This attribute, interpreted as
a percentage of font point size, controls the text drawing mode: positive
values effect drawing with stroke only; negative values are for stroke and fill.
A typical value for outlined text is 3.0.
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0
*/
@property (nullable, nonatomic, readonly) NSNumber *as_strokeWidth;
- (nullable NSNumber *)as_strokeWidthAtIndex:(NSUInteger)index;
/**
The stroke color. (read-only)
@discussion Default value is nil (same as foreground color).
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0
*/
@property (nullable, nonatomic, readonly) UIColor *as_strokeColor;
- (nullable UIColor *)as_strokeColorAtIndex:(NSUInteger)index;
/**
The text shadow. (read-only)
@discussion Default value is nil (no shadow).
@discussion Get this property returns the first character's attribute.
@since UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) NSShadow *as_shadow;
- (nullable NSShadow *)as_shadowAtIndex:(NSUInteger)index;
/**
The strikethrough style. (read-only)
@discussion Default value is NSUnderlineStyleNone (no strikethrough).
@discussion Get this property returns the first character's attribute.
@since UIKit:6.0
*/
@property (nonatomic, readonly) NSUnderlineStyle as_strikethroughStyle;
- (NSUnderlineStyle)as_strikethroughStyleAtIndex:(NSUInteger)index;
/**
The strikethrough color. (read-only)
@discussion Default value is nil (same as foreground color).
@discussion Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic, readonly) UIColor *as_strikethroughColor;
- (nullable UIColor *)as_strikethroughColorAtIndex:(NSUInteger)index;
/**
The underline style. (read-only)
@discussion Default value is NSUnderlineStyleNone (no underline).
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0
*/
@property (nonatomic, readonly) NSUnderlineStyle as_underlineStyle;
- (NSUnderlineStyle)as_underlineStyleAtIndex:(NSUInteger)index;
/**
The underline color. (read-only)
@discussion Default value is nil (same as foreground color).
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:7.0
*/
@property (nullable, nonatomic, readonly) UIColor *as_underlineColor;
- (nullable UIColor *)as_underlineColorAtIndex:(NSUInteger)index;
/**
Ligature formation control. (read-only)
@discussion Default is int value 1. The ligature attribute determines what kinds
of ligatures should be used when displaying the string. A value of 0 indicates
that only ligatures essential for proper rendering of text should be used,
1 indicates that standard ligatures should be used, and 2 indicates that all
available ligatures should be used. Which ligatures are standard depends on the
script and possibly the font.
@discussion Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) NSNumber *as_ligature;
- (nullable NSNumber *)as_ligatureAtIndex:(NSUInteger)index;
/**
The text effect. (read-only)
@discussion Default is nil (no effect). The only currently supported value
is NSTextEffectLetterpressStyle.
@discussion Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic, readonly) NSString *as_textEffect;
- (nullable NSString *)as_textEffectAtIndex:(NSUInteger)index;
/**
The skew to be applied to glyphs. (read-only)
@discussion Default is 0 (no skew).
@discussion Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic, readonly) NSNumber *as_obliqueness;
- (nullable NSNumber *)as_obliquenessAtIndex:(NSUInteger)index;
/**
The log of the expansion factor to be applied to glyphs. (read-only)
@discussion Default is 0 (no expansion).
@discussion Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic, readonly) NSNumber *as_expansion;
- (nullable NSNumber *)as_expansionAtIndex:(NSUInteger)index;
/**
The character's offset from the baseline, in points. (read-only)
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic, readonly) NSNumber *as_baselineOffset;
- (nullable NSNumber *)as_baselineOffsetAtIndex:(NSUInteger)index;
/**
Glyph orientation control. (read-only)
@discussion Default is NO. A value of NO indicates that horizontal glyph forms
are to be used, YES indicates that vertical glyph forms are to be used.
@discussion Get this property returns the first character's attribute.
@since CoreText:4.3 ASText:6.0
*/
@property (nonatomic, readonly) BOOL as_verticalGlyphForm;
- (BOOL)as_verticalGlyphFormAtIndex:(NSUInteger)index;
/**
Specifies text language. (read-only)
@discussion Value must be a NSString containing a locale identifier. Default is
unset. When this attribute is set to a valid identifier, it will be used to select
localized glyphs (if supported by the font) and locale-specific line breaking rules.
@discussion Get this property returns the first character's attribute.
@since CoreText:7.0 ASText:7.0
*/
@property (nullable, nonatomic, readonly) NSString *as_language;
- (nullable NSString *)as_languageAtIndex:(NSUInteger)index;
/**
Specifies a bidirectional override or embedding. (read-only)
@discussion See alse NSWritingDirection and NSWritingDirectionAttributeName.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:7.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) NSArray<NSNumber *> *as_writingDirection;
- (nullable NSArray<NSNumber *> *)as_writingDirectionAtIndex:(NSUInteger)index;
/**
An NSParagraphStyle object which is used to specify things like
line alignment, tab rulers, writing direction, etc. (read-only)
@discussion Default is nil ([NSParagraphStyle defaultParagraphStyle]).
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic, readonly) NSParagraphStyle *as_paragraphStyle;
- (nullable NSParagraphStyle *)as_paragraphStyleAtIndex:(NSUInteger)index;
#pragma mark - Get paragraph attribute as property
///=============================================================================
/// @name Get paragraph attribute as property
///=============================================================================
/**
The text alignment (A wrapper for NSParagraphStyle). (read-only)
@discussion Natural text alignment is realized as left or right alignment
depending on the line sweep direction of the first script contained in the paragraph.
@discussion Default is NSTextAlignmentNatural.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) NSTextAlignment as_alignment;
- (NSTextAlignment)as_alignmentAtIndex:(NSUInteger)index;
/**
The mode that should be used to break lines (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the line break mode to be used laying out the paragraph's text.
@discussion Default is NSLineBreakByWordWrapping.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) NSLineBreakMode as_lineBreakMode;
- (NSLineBreakMode)as_lineBreakModeAtIndex:(NSUInteger)index;
/**
The distance in points between the bottom of one line fragment and the top of the next.
(A wrapper for NSParagraphStyle) (read-only)
@discussion This value is always nonnegative. This value is included in the line
fragment heights in the layout manager.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_lineSpacing;
- (CGFloat)as_lineSpacingAtIndex:(NSUInteger)index;
/**
The space after the end of the paragraph (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the space (measured in points) added at the
end of the paragraph to separate it from the following paragraph. This value must
be nonnegative. The space between paragraphs is determined by adding the previous
paragraph's paragraphSpacing and the current paragraph's paragraphSpacingBefore.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_paragraphSpacing;
- (CGFloat)as_paragraphSpacingAtIndex:(NSUInteger)index;
/**
The distance between the paragraph's top and the beginning of its text content.
(A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the space (measured in points) between the
paragraph's top and the beginning of its text content.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_paragraphSpacingBefore;
- (CGFloat)as_paragraphSpacingBeforeAtIndex:(NSUInteger)index;
/**
The indentation of the first line (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the distance (in points) from the leading margin
of a text container to the beginning of the paragraph's first line. This value
is always nonnegative.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_firstLineHeadIndent;
- (CGFloat)as_firstLineHeadIndentAtIndex:(NSUInteger)index;
/**
The indentation of the receiver's lines other than the first. (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the distance (in points) from the leading margin
of a text container to the beginning of lines other than the first. This value is
always nonnegative.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_headIndent;
- (CGFloat)as_headIndentAtIndex:(NSUInteger)index;
/**
The trailing indentation (A wrapper for NSParagraphStyle). (read-only)
@discussion If positive, this value is the distance from the leading margin
(for example, the left margin in left-to-right text). If 0 or negative, it's the
distance from the trailing margin.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_tailIndent;
- (CGFloat)as_tailIndentAtIndex:(NSUInteger)index;
/**
The receiver's minimum height (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the minimum height in points that any line in
the receiver will occupy, regardless of the font size or size of any attached graphic.
This value must be nonnegative.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_minimumLineHeight;
- (CGFloat)as_minimumLineHeightAtIndex:(NSUInteger)index;
/**
The receiver's maximum line height (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the maximum height in points that any line in
the receiver will occupy, regardless of the font size or size of any attached graphic.
This value is always nonnegative. Glyphs and graphics exceeding this height will
overlap neighboring lines; however, a maximum height of 0 implies no line height limit.
Although this limit applies to the line itself, line spacing adds extra space between adjacent lines.
@discussion Default is 0 (no limit).
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_maximumLineHeight;
- (CGFloat)as_maximumLineHeightAtIndex:(NSUInteger)index;
/**
The line height multiple (A wrapper for NSParagraphStyle). (read-only)
@discussion This property contains the line break mode to be used laying out the paragraph's text.
@discussion Default is 0 (no multiple).
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) CGFloat as_lineHeightMultiple;
- (CGFloat)as_lineHeightMultipleAtIndex:(NSUInteger)index;
/**
The base writing direction (A wrapper for NSParagraphStyle). (read-only)
@discussion If you specify NSWritingDirectionNaturalDirection, the receiver resolves
the writing direction to either NSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
depending on the direction for the user's `language` preference setting.
@discussion Default is NSWritingDirectionNatural.
@discussion Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic, readonly) NSWritingDirection as_baseWritingDirection;
- (NSWritingDirection)as_baseWritingDirectionAtIndex:(NSUInteger)index;
/**
The paragraph's threshold for hyphenation. (A wrapper for NSParagraphStyle). (read-only)
@discussion Valid values lie between 0.0 and 1.0 inclusive. Hyphenation is attempted
when the ratio of the text width (as broken without hyphenation) to the width of the
line fragment is less than the hyphenation factor. When the paragraph's hyphenation
factor is 0.0, the layout manager's hyphenation factor is used instead. When both
are 0.0, hyphenation is disabled.
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since UIKit:6.0
*/
@property (nonatomic, readonly) float as_hyphenationFactor;
- (float)as_hyphenationFactorAtIndex:(NSUInteger)index;
/**
The document-wide default tab interval (A wrapper for NSParagraphStyle). (read-only)
@discussion This property represents the default tab interval in points. Tabs after the
last specified in tabStops are placed at integer multiples of this distance (if positive).
@discussion Default is 0.
@discussion Get this property returns the first character's attribute.
@since CoreText:7.0 UIKit:7.0 ASText:7.0
*/
@property (nonatomic, readonly) CGFloat as_defaultTabInterval;
- (CGFloat)as_defaultTabIntervalAtIndex:(NSUInteger)index;
/**
An array of NSTextTab objects representing the receiver's tab stops.
(A wrapper for NSParagraphStyle). (read-only)
@discussion The NSTextTab objects, sorted by location, define the tab stops for
the paragraph style.
@discussion Default is 12 TabStops with 28.0 tab interval.
@discussion Get this property returns the first character's attribute.
@since CoreText:7.0 UIKit:7.0 ASText:7.0
*/
@property (nullable, nonatomic, copy, readonly) NSArray<NSTextTab *> *as_tabStops;
- (nullable NSArray<NSTextTab *> *)as_tabStopsAtIndex:(NSUInteger)index;
#pragma mark - Get ASText attribute as property
///=============================================================================
/// @name Get ASText attribute as property
///=============================================================================
/**
The text shadow. (read-only)
@discussion Default value is nil (no shadow).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nullable, nonatomic, readonly) ASTextShadow *as_textShadow;
- (nullable ASTextShadow *)as_textShadowAtIndex:(NSUInteger)index;
/**
The text inner shadow. (read-only)
@discussion Default value is nil (no shadow).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nullable, nonatomic, readonly) ASTextShadow *as_textInnerShadow;
- (nullable ASTextShadow *)as_textInnerShadowAtIndex:(NSUInteger)index;
/**
The text underline. (read-only)
@discussion Default value is nil (no underline).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nullable, nonatomic, readonly) ASTextDecoration *as_textUnderline;
- (nullable ASTextDecoration *)as_textUnderlineAtIndex:(NSUInteger)index;
/**
The text strikethrough. (read-only)
@discussion Default value is nil (no strikethrough).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nullable, nonatomic, readonly) ASTextDecoration *as_textStrikethrough;
- (nullable ASTextDecoration *)as_textStrikethroughAtIndex:(NSUInteger)index;
/**
The text border. (read-only)
@discussion Default value is nil (no border).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nullable, nonatomic, readonly) ASTextBorder *as_textBorder;
- (nullable ASTextBorder *)as_textBorderAtIndex:(NSUInteger)index;
/**
The text background border. (read-only)
@discussion Default value is nil (no background border).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nullable, nonatomic, readonly) ASTextBorder *as_textBackgroundBorder;
- (nullable ASTextBorder *)as_textBackgroundBorderAtIndex:(NSUInteger)index;
/**
The glyph transform. (read-only)
@discussion Default value is CGAffineTransformIdentity (no transform).
@discussion Get this property returns the first character's attribute.
@since ASText:6.0
*/
@property (nonatomic, readonly) CGAffineTransform as_textGlyphTransform;
- (CGAffineTransform)as_textGlyphTransformAtIndex:(NSUInteger)index;
#pragma mark - Query for ASText
///=============================================================================
/// @name Query for ASText
///=============================================================================
/**
Returns the plain text from a range.
If there's `ASTextBackedStringAttributeName` attribute, the backed string will
replace the attributed string range.
@param range A range in receiver.
@return The plain text.
*/
- (nullable NSString *)as_plainTextForRange:(NSRange)range;
#pragma mark - Create attachment string for ASText
///=============================================================================
/// @name Create attachment string for ASText
///=============================================================================
/**
Creates and returns an attachment.
@param content The attachment (UIImage/UIView/CALayer).
@param contentMode The attachment's content mode.
@param width The attachment's container width in layout.
@param ascent The attachment's container ascent in layout.
@param descent The attachment's container descent in layout.
@return An attributed string, or nil if an error occurs.
@since ASText:6.0
*/
+ (NSMutableAttributedString *)as_attachmentStringWithContent:(nullable id)content
contentMode:(UIViewContentMode)contentMode
width:(CGFloat)width
ascent:(CGFloat)ascent
descent:(CGFloat)descent;
/**
Creates and returns an attachment.
Example: ContentMode:bottom Alignment:Top.
The text The attachment holder
↓ ↓
─────────┌──────────────────────┐───────
/ \ │ │ / ___|
/ _ \ │ │| |
/ ___ \ │ │| |___ ←── The text line
/_/ \_\│ ██████████████ │ \____|
─────────│ ██████████████ │───────
│ ██████████████ │
│ ██████████████ ←───────────────── The attachment content
│ ██████████████ │
└──────────────────────┘
@param content The attachment (UIImage/UIView/CALayer).
@param contentMode The attachment's content mode in attachment holder
@param attachmentSize The attachment holder's size in text layout.
@param font The attachment will align to this font.
@param alignment The attachment holder's alignment to text line.
@return An attributed string, or nil if an error occurs.
@since ASText:6.0
*/
+ (NSMutableAttributedString *)as_attachmentStringWithContent:(nullable id)content
contentMode:(UIViewContentMode)contentMode
attachmentSize:(CGSize)attachmentSize
alignToFont:(UIFont *)font
alignment:(ASTextVerticalAlignment)alignment;
/**
Creates and returns an attahment from a fourquare image as if it was an emoji.
@param image A fourquare image.
@param fontSize The font size.
@return An attributed string, or nil if an error occurs.
@since ASText:6.0
*/
+ (nullable NSMutableAttributedString *)as_attachmentStringWithEmojiImage:(UIImage *)image
fontSize:(CGFloat)fontSize;
#pragma mark - Utility
///=============================================================================
/// @name Utility
///=============================================================================
/**
Returns NSMakeRange(0, self.length).
*/
- (NSRange)as_rangeOfAll;
/**
If YES, it share the same attribute in entire text range.
*/
- (BOOL)as_isSharedAttributesInAllRange;
/**
If YES, it can be drawn with the [drawWithRect:options:context:] method or displayed with UIKit.
If NO, it should be drawn with CoreText or ASText.
@discussion If the method returns NO, it means that there's at least one attribute
which is not supported by UIKit (such as CTParagraphStyleRef). If display this string
in UIKit, it may lose some attribute, or even crash the app.
*/
- (BOOL)as_canDrawWithUIKit;
@end
/**
Set pre-defined attributes to attributed string.
All properties defined in UIKit, CoreText and ASText are included.
*/
@interface NSMutableAttributedString (ASText)
#pragma mark - Set character attribute
///=============================================================================
/// @name Set character attribute
///=============================================================================
/**
Sets the attributes to the entire text string.
@discussion The old attributes will be removed.
@param attributes A dictionary containing the attributes to set, or nil to remove all attributes.
*/
- (void)as_setAttributes:(nullable NSDictionary<NSString *, id> *)attributes;
- (void)setAs_attributes:(nullable NSDictionary<NSString *, id> *)attributes;
/**
Sets an attribute with the given name and value to the entire text string.
@param name A string specifying the attribute name.
@param value The attribute value associated with name. Pass `nil` or `NSNull` to
remove the attribute.
*/
- (void)as_setAttribute:(NSString *)name value:(nullable id)value;
/**
Sets an attribute with the given name and value to the characters in the specified range.
@param name A string specifying the attribute name.
@param value The attribute value associated with name. Pass `nil` or `NSNull` to
remove the attribute.
@param range The range of characters to which the specified attribute/value pair applies.
*/
- (void)as_setAttribute:(NSString *)name value:(nullable id)value range:(NSRange)range;
/**
Removes all attributes in the specified range.
@param range The range of characters.
*/
- (void)as_removeAttributesInRange:(NSRange)range;
#pragma mark - Set character attribute as property
///=============================================================================
/// @name Set character attribute as property
///=============================================================================
/**
The font of the text.
@discussion Default is Helvetica (Neue) 12.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) UIFont *as_font;
- (void)as_setFont:(nullable UIFont *)font range:(NSRange)range;
/**
A kerning adjustment.
@discussion Default is standard kerning. The kerning attribute indicate how many
points the following character should be shifted from its default offset as
defined by the current character's font in points; a positive kern indicates a
shift farther along and a negative kern indicates a shift closer to the current
character. If this attribute is not present, standard kerning will be used.
If this attribute is set to 0.0, no kerning will be done at all.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) NSNumber *as_kern;
- (void)as_setKern:(nullable NSNumber *)kern range:(NSRange)range;
/**
The foreground color.
@discussion Default is Black.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) UIColor *as_color;
- (void)as_setColor:(nullable UIColor *)color range:(NSRange)range;
/**
The background color.
@discussion Default is nil (or no background).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:6.0
*/
@property (nullable, nonatomic) UIColor *as_backgroundColor;
- (void)as_setBackgroundColor:(nullable UIColor *)backgroundColor range:(NSRange)range;
/**
The stroke width.
@discussion Default value is 0.0 (no stroke). This attribute, interpreted as
a percentage of font point size, controls the text drawing mode: positive
values effect drawing with stroke only; negative values are for stroke and fill.
A typical value for outlined text is 3.0.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) NSNumber *as_strokeWidth;
- (void)as_setStrokeWidth:(nullable NSNumber *)strokeWidth range:(NSRange)range;
/**
The stroke color.
@discussion Default value is nil (same as foreground color).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) UIColor *as_strokeColor;
- (void)as_setStrokeColor:(nullable UIColor *)strokeColor range:(NSRange)range;
/**
The text shadow.
@discussion Default value is nil (no shadow).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) NSShadow *as_shadow;
- (void)as_setShadow:(nullable NSShadow *)shadow range:(NSRange)range;
/**
The strikethrough style.
@discussion Default value is NSUnderlineStyleNone (no strikethrough).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:6.0
*/
@property (nonatomic) NSUnderlineStyle as_strikethroughStyle;
- (void)as_setStrikethroughStyle:(NSUnderlineStyle)strikethroughStyle range:(NSRange)range;
/**
The strikethrough color.
@discussion Default value is nil (same as foreground color).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic) UIColor *as_strikethroughColor;
- (void)as_setStrikethroughColor:(nullable UIColor *)strikethroughColor range:(NSRange)range NS_AVAILABLE_IOS(7_0);
/**
The underline style.
@discussion Default value is NSUnderlineStyleNone (no underline).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0
*/
@property (nonatomic) NSUnderlineStyle as_underlineStyle;
- (void)as_setUnderlineStyle:(NSUnderlineStyle)underlineStyle range:(NSRange)range;
/**
The underline color.
@discussion Default value is nil (same as foreground color).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:7.0
*/
@property (nullable, nonatomic) UIColor *as_underlineColor;
- (void)as_setUnderlineColor:(nullable UIColor *)underlineColor range:(NSRange)range;
/**
Ligature formation control.
@discussion Default is int value 1. The ligature attribute determines what kinds
of ligatures should be used when displaying the string. A value of 0 indicates
that only ligatures essential for proper rendering of text should be used,
1 indicates that standard ligatures should be used, and 2 indicates that all
available ligatures should be used. Which ligatures are standard depends on the
script and possibly the font.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:3.2 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) NSNumber *as_ligature;
- (void)as_setLigature:(nullable NSNumber *)ligature range:(NSRange)range;
/**
The text effect.
@discussion Default is nil (no effect). The only currently supported value
is NSTextEffectLetterpressStyle.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic) NSString *as_textEffect;
- (void)as_setTextEffect:(nullable NSString *)textEffect range:(NSRange)range NS_AVAILABLE_IOS(7_0);
/**
The skew to be applied to glyphs.
@discussion Default is 0 (no skew).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic) NSNumber *as_obliqueness;
- (void)as_setObliqueness:(nullable NSNumber *)obliqueness range:(NSRange)range NS_AVAILABLE_IOS(7_0);
/**
The log of the expansion factor to be applied to glyphs.
@discussion Default is 0 (no expansion).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic) NSNumber *as_expansion;
- (void)as_setExpansion:(nullable NSNumber *)expansion range:(NSRange)range NS_AVAILABLE_IOS(7_0);
/**
The character's offset from the baseline, in points.
@discussion Default is 0.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since UIKit:7.0
*/
@property (nullable, nonatomic) NSNumber *as_baselineOffset;
- (void)as_setBaselineOffset:(nullable NSNumber *)baselineOffset range:(NSRange)range NS_AVAILABLE_IOS(7_0);
/**
Glyph orientation control.
@discussion Default is NO. A value of NO indicates that horizontal glyph forms
are to be used, YES indicates that vertical glyph forms are to be used.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:4.3 ASText:6.0
*/
@property (nonatomic) BOOL as_verticalGlyphForm;
- (void)as_setVerticalGlyphForm:(BOOL)verticalGlyphForm range:(NSRange)range;
/**
Specifies text language.
@discussion Value must be a NSString containing a locale identifier. Default is
unset. When this attribute is set to a valid identifier, it will be used to select
localized glyphs (if supported by the font) and locale-specific line breaking rules.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:7.0 ASText:7.0
*/
@property (nullable, nonatomic) NSString *as_language;
- (void)as_setLanguage:(nullable NSString *)language range:(NSRange)range NS_AVAILABLE_IOS(7_0);
/**
Specifies a bidirectional override or embedding.
@discussion See alse NSWritingDirection and NSWritingDirectionAttributeName.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:7.0 ASText:6.0
*/
@property (nullable, nonatomic) NSArray<NSNumber *> *as_writingDirection;
- (void)as_setWritingDirection:(nullable NSArray<NSNumber *> *)writingDirection range:(NSRange)range;
/**
An NSParagraphStyle object which is used to specify things like
line alignment, tab rulers, writing direction, etc.
@discussion Default is nil ([NSParagraphStyle defaultParagraphStyle]).
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nullable, nonatomic) NSParagraphStyle *as_paragraphStyle;
- (void)as_setParagraphStyle:(nullable NSParagraphStyle *)paragraphStyle range:(NSRange)range;
#pragma mark - Set paragraph attribute as property
///=============================================================================
/// @name Set paragraph attribute as property
///=============================================================================
/**
The text alignment (A wrapper for NSParagraphStyle).
@discussion Natural text alignment is realized as left or right alignment
depending on the line sweep direction of the first script contained in the paragraph.
@discussion Default is NSTextAlignmentNatural.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic) NSTextAlignment as_alignment;
- (void)as_setAlignment:(NSTextAlignment)alignment range:(NSRange)range;
/**
The mode that should be used to break lines (A wrapper for NSParagraphStyle).
@discussion This property contains the line break mode to be used laying out the paragraph's text.
@discussion Default is NSLineBreakByWordWrapping.
@discussion Set this property applies to the entire text string.
Get this property returns the first character's attribute.
@since CoreText:6.0 UIKit:6.0 ASText:6.0
*/
@property (nonatomic) NSLineBreakMode as_lineBreakMode;
- (void)as_setLineBreakMode:(NSLineBreakMode)lineBreakMode range:(NSRange)range;
/**
The distance in points between the bottom of one line fragment and the top of the next.
(A wrapper for NSParagraphStyle)
@discussion This value is always nonnegative. This value is included in the line