summaryrefslogtreecommitdiff
path: root/pango2/pango-attributes.c
blob: 749af63facb0c0b1f237466a8a68396d48763686 (plain)
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
/* Pango2
 * pango-attributes.c: Attributed text
 *
 * Copyright (C) 2000-2002 Red Hat Software
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"
#include <string.h>

#include "pango-attributes-private.h"
#include "pango-attr-private.h"
#include "pango-impl-utils.h"

/* {{{ Attribute value types */

static inline Pango2Attribute *
pango2_attr_init (Pango2AttrType type)
{
  Pango2Attribute *attr;

  attr = g_slice_new (Pango2Attribute);
  attr->type = type;
  attr->start_index = PANGO2_ATTR_INDEX_FROM_TEXT_BEGINNING;
  attr->end_index = PANGO2_ATTR_INDEX_TO_TEXT_END;

  return attr;
}

static inline Pango2Attribute *
pango2_attr_string_new (Pango2AttrType  type,
                        const char     *value)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_STRING, NULL);

  attr = pango2_attr_init (type);
  attr->str_value = g_strdup (value);

  return attr;
}

static inline Pango2Attribute *
pango2_attr_int_new (Pango2AttrType type,
                     int            value)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_INT, NULL);

  attr = pango2_attr_init (type);
  attr->int_value = value;

  return attr;
}

static inline Pango2Attribute *
pango2_attr_boolean_new (Pango2AttrType type,
                         gboolean       value)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_BOOLEAN, NULL);

  attr = pango2_attr_init (type);
  attr->boolean_value = value;

  return attr;
}

static inline Pango2Attribute *
pango2_attr_float_new (Pango2AttrType type,
                       double         value)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_FLOAT, NULL);

  attr = pango2_attr_init (type);
  attr->double_value = value;

  return attr;
}

static inline Pango2Attribute *
pango2_attr_color_new (Pango2AttrType  type,
                       Pango2Color    *color)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_COLOR, NULL);

  attr = pango2_attr_init (type);
  attr->color_value = *color;

  return attr;
}

static inline Pango2Attribute *
pango2_attr_lang_new (Pango2AttrType  type,
                      Pango2Language *value)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_LANGUAGE, NULL);

  attr = pango2_attr_init (type);
  attr->lang_value  = value;

  return attr;
}

static inline Pango2Attribute *
pango2_attr_font_description_new (Pango2AttrType               type,
                                  const Pango2FontDescription *value)
{
  Pango2Attribute *attr;

  g_return_val_if_fail (PANGO2_ATTR_TYPE_VALUE_TYPE (type) == PANGO2_ATTR_VALUE_FONT_DESC, NULL);

  attr = pango2_attr_init (type);
  attr->font_value  = pango2_font_description_copy (value);

  return attr;
}

/* }}} */
/* {{{ Attribute types */

/**
 * pango2_attr_family_new:
 * @family: the family or comma-separated list of families
 *
 * Create a new font family attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_family_new (const char *family)
{
  return pango2_attr_string_new (PANGO2_ATTR_FAMILY, family);
}

/**
 * pango2_attr_language_new:
 * @language: language tag
 *
 * Create a new language tag attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_language_new (Pango2Language *language)
{
  return pango2_attr_lang_new (PANGO2_ATTR_LANGUAGE, language);
}

/**
 * pango2_attr_foreground_new:
 * @color: the color
 *
 * Create a new foreground color attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_foreground_new (Pango2Color *color)
{
  return pango2_attr_color_new (PANGO2_ATTR_FOREGROUND, color);
}

/**
 * pango2_attr_background_new:
 * @color: the color
 *
 * Create a new background color attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_background_new (Pango2Color *color)
{
  return pango2_attr_color_new (PANGO2_ATTR_BACKGROUND, color);
}

/**
 * pango2_attr_size_new:
 * @size: the font size, in %PANGO2_SCALE-ths of a point
 *
 * Create a new font-size attribute in fractional points.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_size_new (int value)
{
  return pango2_attr_int_new (PANGO2_ATTR_SIZE, value);
}


/**
 * pango2_attr_size_new_absolute:
 * @size: the font size, in %PANGO2_SCALE-ths of a device unit
 *
 * Create a new font-size attribute in device units.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_size_new_absolute (int size)
{
  return pango2_attr_int_new (PANGO2_ATTR_ABSOLUTE_SIZE, size);
}

/**
 * pango2_attr_style_new:
 * @style: the slant style
 *
 * Create a new font slant style attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_style_new (Pango2Style style)
{
  return pango2_attr_int_new (PANGO2_ATTR_STYLE, (int)style);
}

/**
 * pango2_attr_weight_new:
 * @weight: the weight
 *
 * Create a new font weight attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_weight_new (Pango2Weight weight)
{
  return pango2_attr_int_new (PANGO2_ATTR_WEIGHT, (int)weight);
}

/**
 * pango2_attr_variant_new:
 * @variant: the variant
 *
 * Create a new font variant attribute (normal or small caps).
 *
 * Return value: (transfer full): the newly allocated `Pango2Attribute`,
 *   which should be freed with [method@Pango2.Attribute.destroy].
 */
Pango2Attribute *
pango2_attr_variant_new (Pango2Variant variant)
{
  return pango2_attr_int_new (PANGO2_ATTR_VARIANT, (int)variant);
}

/**
 * pango2_attr_stretch_new:
 * @stretch: the stretch
 *
 * Create a new font stretch attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_stretch_new (Pango2Stretch stretch)
{
  return pango2_attr_int_new (PANGO2_ATTR_STRETCH, (int)stretch);
}

/**
 * pango2_attr_font_desc_new:
 * @desc: the font description
 *
 * Create a new font description attribute.
 *
 * This attribute allows setting family, style, weight, variant,
 * stretch, and size simultaneously.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_font_desc_new (const Pango2FontDescription *desc)
{
  return pango2_attr_font_description_new (PANGO2_ATTR_FONT_DESC, desc);
}

/**
 * pango2_attr_underline_new:
 * @style: the line style
 *
 * Create a new underline attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_underline_new (Pango2LineStyle style)
{
  return pango2_attr_int_new (PANGO2_ATTR_UNDERLINE, (int)style);
}

/**
 * pango2_attr_underline_color_new:
 * @color: the color
 *
 * Create a new underline color attribute.
 *
 * This attribute modifies the color of underlines.
 * If not set, underlines will use the foreground color.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_underline_color_new (Pango2Color *color)
{
  return pango2_attr_color_new (PANGO2_ATTR_UNDERLINE_COLOR, color);
}

/**
 * pango2_attr_underline_position_new:
 * @position: the underline position
 *
 * Create a new underline position attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_underline_position_new (Pango2UnderlinePosition position)
{
  return pango2_attr_int_new (PANGO2_ATTR_UNDERLINE_POSITION, (int)position);
}
/**
 * pango2_attr_strikethrough_new:
 * @style: the line style
 *
 * Create a new strike-through attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_strikethrough_new (Pango2LineStyle style)
{
  return pango2_attr_int_new (PANGO2_ATTR_STRIKETHROUGH, (int)style);
}

/**
 * pango2_attr_strikethrough_color_new:
 * @color: the color
 *
 * Create a new strikethrough color attribute.
 *
 * This attribute modifies the color of strikethrough lines.
 * If not set, strikethrough lines will use the foreground color.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_strikethrough_color_new (Pango2Color *color)
{
  return pango2_attr_color_new (PANGO2_ATTR_STRIKETHROUGH_COLOR, color);
}

/**
 * pango2_attr_rise_new:
 * @rise: the amount that the text should be displaced vertically,
 *   in Pango units. Positive values displace the text upwards.
 *
 * Create a new baseline displacement attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_rise_new (int rise)
{
  return pango2_attr_int_new (PANGO2_ATTR_RISE, (int)rise);
}

/**
 * pango2_attr_baseline_shift_new:
 * @shift: either a `Pango2BaselineShift` enumeration value or an absolute value (> 1024)
 *   in Pango units, relative to the baseline of the previous run.
 *   Positive values displace the text upwards.
 *
 * Create a new baseline displacement attribute.
 *
 * The effect of this attribute is to shift the baseline of a run,
 * relative to the run of preceding run.
 *
 * <picture>
 *   <source srcset="baseline-shift-dark.png" media="(prefers-color-scheme: dark)">
 *   <img alt="Baseline Shift" src="baseline-shift-light.png">
 * </picture>

 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_baseline_shift_new (int rise)
{
  return pango2_attr_int_new (PANGO2_ATTR_BASELINE_SHIFT, (int)rise);
}

/**
 * pango2_attr_font_scale_new:
 * @scale: a `Pango2FontScale` value, which indicates font size change relative
 *   to the size of the previous run.
 *
 * Create a new font scale attribute.
 *
 * The effect of this attribute is to change the font size of a run,
 * relative to the size of preceding run.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_font_scale_new (Pango2FontScale scale)
{
  return pango2_attr_int_new (PANGO2_ATTR_FONT_SCALE, (int)scale);
}

/**
 * pango2_attr_scale_new:
 * @scale_factor: factor to scale the font
 *
 * Create a new font size scale attribute.
 *
 * The base font for the affected text will have
 * its size multiplied by @scale_factor.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute*
pango2_attr_scale_new (double scale_factor)
{
  return pango2_attr_float_new (PANGO2_ATTR_SCALE, scale_factor);
}

/**
 * pango2_attr_fallback_new:
 * @enable_fallback: %TRUE if we should fall back on other fonts
 *   for characters the active font is missing
 *
 * Create a new font fallback attribute.
 *
 * If fallback is disabled, characters will only be
 * used from the closest matching font on the system.
 * No fallback will be done to other fonts on the system
 * that might contain the characters in the text.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_fallback_new (gboolean enable_fallback)
{
  return pango2_attr_boolean_new (PANGO2_ATTR_FALLBACK, enable_fallback);
}

/**
 * pango2_attr_letter_spacing_new:
 * @letter_spacing: amount of extra space to add between
 *   graphemes of the text, in Pango units
 *
 * Create a new letter-spacing attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_letter_spacing_new (int letter_spacing)
{
  return pango2_attr_int_new (PANGO2_ATTR_LETTER_SPACING, letter_spacing);
}

/**
 * pango2_attr_gravity_new:
 * @gravity: the gravity value; should not be %PANGO2_GRAVITY_AUTO
 *
 * Create a new gravity attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_gravity_new (Pango2Gravity gravity)
{
  g_return_val_if_fail (gravity != PANGO2_GRAVITY_AUTO, NULL);

  return pango2_attr_int_new (PANGO2_ATTR_GRAVITY, (int)gravity);
}

/**
 * pango2_attr_gravity_hint_new:
 * @hint: the gravity hint value
 *
 * Create a new gravity hint attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_gravity_hint_new (Pango2GravityHint hint)
{
  return pango2_attr_int_new (PANGO2_ATTR_GRAVITY_HINT, (int)hint);
}

/**
 * pango2_attr_font_features_new:
 * @features: a string with OpenType font features, with the syntax of the [CSS
 *   font-feature-settings property](https://www.w3.org/TR/css-fonts-4/#font-rend-desc)
 *
 * Create a new font features tag attribute.
 *
 * You can use this attribute to select OpenType font features like small-caps,
 * alternative glyphs, ligatures, etc. for fonts that support them.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_font_features_new (const char *features)
{
  g_return_val_if_fail (features != NULL, NULL);

  return pango2_attr_string_new (PANGO2_ATTR_FONT_FEATURES, features);
}

/**
 * pango2_attr_palette_new:
 * @palette : name of palette to use
 *
 * Create a new palette attribute.
 *
 * You can use this attribute to select font color palettes
 * by name, like "light", "dark" or "palette3".
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_palette_new (const char *palette)
{
  g_return_val_if_fail (palette != NULL, NULL);

  return pango2_attr_string_new (PANGO2_ATTR_PALETTE, palette);
}

/**
 * pango2_attr_allow_breaks_new:
 * @allow_breaks: %TRUE if we line breaks are allowed
 *
 * Create a new allow-breaks attribute.
 *
 * If breaks are disabled, the range will be kept in a
 * single run, as far as possible.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_allow_breaks_new (gboolean allow_breaks)
{
  return pango2_attr_boolean_new (PANGO2_ATTR_ALLOW_BREAKS, allow_breaks);
}

/**
 * pango2_attr_insert_hyphens_new:
 * @insert_hyphens: %TRUE if hyphens should be inserted
 *
 * Create a new insert-hyphens attribute.
 *
 * Pango will insert hyphens when breaking lines in
 * the middle of a word. This attribute can be used
 * to suppress the hyphen.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_insert_hyphens_new (gboolean insert_hyphens)
{
  return pango2_attr_boolean_new (PANGO2_ATTR_INSERT_HYPHENS, insert_hyphens);
}

/**
 * pango2_attr_show_new:
 * @flags: `Pango2ShowFlags` to apply
 *
 * Create a new attribute that influences how invisible
 * characters are rendered.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 **/
Pango2Attribute *
pango2_attr_show_new (Pango2ShowFlags flags)
{
  return pango2_attr_int_new (PANGO2_ATTR_SHOW, (int)flags);
}

/**
 * pango2_attr_word_new:
 *
 * Create a new attribute that marks its range
 * as a single word.
 *
 * Note that this may require adjustments to word and
 * sentence classification around the range.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_word_new (void)
{
  return pango2_attr_boolean_new (PANGO2_ATTR_WORD, TRUE);
}

/**
 * pango2_attr_sentence_new:
 *
 * Create a new attribute that marks its range
 * as a single sentence.
 *
 * Note that this may require adjustments to word and
 * sentence classification around the range.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_sentence_new (void)
{
  return pango2_attr_boolean_new (PANGO2_ATTR_SENTENCE, TRUE);
}

/**
 * pango2_attr_paragraph_new:
 *
 * Create a new attribute that marks its range as a single paragraph.
 *
 * Newlines and similar characters in the range of the attribute
 * will not be treated as paragraph separators.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_paragraph_new (void)
{
  return pango2_attr_boolean_new (PANGO2_ATTR_SENTENCE, TRUE);
}

/**
 * pango2_attr_overline_new:
 * @style: the line style
 *
 * Create a new overline-style attribute.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_overline_new (Pango2LineStyle style)
{
  return pango2_attr_int_new (PANGO2_ATTR_OVERLINE, (int)style);
}

/**
 * pango2_attr_overline_color_new:
 * @color: the color
 *
 * Create a new overline color attribute.
 *
 * This attribute modifies the color of overlines.
 * If not set, overlines will use the foreground color.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_overline_color_new (Pango2Color *color)
{
  return pango2_attr_color_new (PANGO2_ATTR_OVERLINE_COLOR, color);
}

/**
 * pango2_attr_line_height_new:
 * @factor: the scaling factor to apply to the logical height
 *
 * Create a new attribute that modifies the height
 * of logical line extents by a factor.
 *
 * This affects the values returned by
 * [method@Pango2.Line.get_extents] and
 * [method@Pango2.LineIter.get_line_extents].
 */
Pango2Attribute *
pango2_attr_line_height_new (double factor)
{
  return pango2_attr_float_new (PANGO2_ATTR_LINE_HEIGHT, factor);
}

/**
 * pango2_attr_line_height_new_absolute:
 * @height: the line height, in %PANGO2_SCALE-ths of a point
 *
 * Create a new attribute that overrides the height
 * of logical line extents to be @height.
 *
 * This affects the values returned by
 * [method@Pango2.Line.get_extents],
 * [method@Pango2.LineIter.get_line_extents].
 */
Pango2Attribute *
pango2_attr_line_height_new_absolute (int height)
{
  return pango2_attr_int_new (PANGO2_ATTR_ABSOLUTE_LINE_HEIGHT, height);
}

/**
 * pango2_attr_line_spacing_new:
 * @spacing: the line spacing, in %PANGO2_SCALE-ths of a point
 *
 * Create a new attribute that adds space to the
 * leading from font metrics, if not overridden
 * by line spacing attributes.
 *
 * This affects the values returned by
 * [method@Pango2.Line.get_extents],
 * [method@Pango2.LineIter.get_line_extents].
 */
Pango2Attribute *
pango2_attr_line_spacing_new (int spacing)
{
  return pango2_attr_int_new (PANGO2_ATTR_LINE_SPACING, spacing);
}

/**
 * pango2_attr_text_transform_new:
 * @transform: `Pango2TextTransform` to apply
 *
 * Create a new attribute that influences how characters
 * are transformed during shaping.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_text_transform_new (Pango2TextTransform transform)
{
  return pango2_attr_int_new (PANGO2_ATTR_TEXT_TRANSFORM, transform);
}

/**
 * pango2_attr_shape_new:
 * @ink_rect: ink rectangle to use for each character
 * @logical_rect: logical rectangle to use for each character
 * @data: user data
 * @copy: (nullable): function to copy @data when the attribute
 *   is copied
 * @destroy: (nullable): function to free @data when the attribute
 *   is freed
 *
 * Creates a new shape attribute.
 *
 * Shape attributes override the extents for a glyph and can
 * trigger custom rendering in a `Pango2Renderer`. This might
 * be used, for instance, for embedding a picture or a widget
 * inside a `Pango2Layout`.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_shape_new (Pango2Rectangle        *ink_rect,
                       Pango2Rectangle        *logical_rect,
                       gpointer                data,
                       Pango2AttrDataCopyFunc  copy,
                       GDestroyNotify          destroy)
{
  Pango2Attribute *attr;
  ShapeData *shape_data;

  shape_data = g_new0 (ShapeData, 1);
  shape_data->ink_rect = *ink_rect;
  shape_data->logical_rect = *logical_rect;
  shape_data->data = data;
  shape_data->copy = copy;
  shape_data->destroy = destroy;

  attr = pango2_attr_init (PANGO2_ATTR_SHAPE);
  attr->pointer_value = shape_data;

  return attr;
}

/**
 * pango2_attr_emoji_presentation_new:
 * @presentation: a `Pango2EmojiPresentation` value
 *
 * Creates a new Emoji presentation attribute.
 *
 * Emoji presentation attributes override the preference for
 * whether Emoji should be presented a text or as color Emoji.
 *
 * Return value: (transfer full): the newly allocated
 *   `Pango2Attribute`, which should be freed with
 *   [method@Pango2.Attribute.destroy]
 */
Pango2Attribute *
pango2_attr_emoji_presentation_new (Pango2EmojiPresentation presentation)
{
  return pango2_attr_int_new (PANGO2_ATTR_EMOJI_PRESENTATION, presentation);
}

/* }}} */
/* {{{ Private API */

gboolean
pango2_attribute_affects_itemization (Pango2Attribute *attr,
                                      gpointer         data)
{
  return (PANGO2_ATTR_AFFECTS (attr) & PANGO2_ATTR_AFFECTS_ITEMIZATION) != 0;
}

gboolean
pango2_attribute_affects_break_or_shape (Pango2Attribute *attr,
                                         gpointer         data)
{
  return (PANGO2_ATTR_AFFECTS (attr) & (PANGO2_ATTR_AFFECTS_BREAKING |
                                       PANGO2_ATTR_AFFECTS_SHAPING)) != 0;
}

/* }}} */

/* vim:set foldmethod=marker expandtab: */