1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module pango.coverage;
7 
8 import pango.utils;
9 import pango.c.coverage;
10 
11 import glib;
12 
13 
14 /**
15 * CoverageLevel:
16 * None: The character is not representable with the font.
17 * Fallback: The character is represented in a way that may be
18 * comprehensible but is not the correct graphical form.
19 * For instance, a Hangul character represented as a
20 * a sequence of Jamos, or a Latin transliteration of a Cyrillic word.
21 * Approximate: The character is represented as basically the correct
22 * graphical form, but with a stylistic variant inappropriate for
23 * the current script.
24 * Exact: The character is represented as the correct graphical form.
25 *
26 * Used to indicate how well a font can represent a particular Unicode
27 * character point for a particular script.
28 */
29 enum CoverageLevel {
30     None        = PangoCoverageLevel.PANGO_COVERAGE_NONE,
31     Fallback    = PangoCoverageLevel.PANGO_COVERAGE_FALLBACK,
32     Approximate = PangoCoverageLevel.PANGO_COVERAGE_APPROXIMATE,
33     Exact       = PangoCoverageLevel.PANGO_COVERAGE_EXACT
34 }
35 
36 /**
37 * PangoCoverage:
38 *
39 * The #PangoCoverage structure represents a map from Unicode characters
40 * to #PangoCoverageLevel. It is an opaque structure with no public fields.
41 */
42 struct Coverage
43 {
44     mixin RefCountedGObj!(PangoCoverage, "pango_coverage");
45 
46 
47     static Coverage create() {
48         return Coverage(pango_coverage_new(), Transfer.Full);
49     }
50 
51     package this(PangoCoverage *ptr, Transfer transfer)
52     {
53         initialize(ptr, transfer);
54     }
55 
56     this(ubyte[] bytes)
57     {
58         initialize(pango_coverage_from_bytes (bytes.ptr, cast(int)bytes.length), Transfer.Full);
59     }
60 
61     Coverage copy()
62     {
63         return Coverage(pango_coverage_copy(nativePtr), Transfer.Full);
64     }
65 
66 
67     CoverageLevel get(int index)
68     {
69         return cast(CoverageLevel)pango_coverage_get(nativePtr, index);
70     }
71 
72     void set(int index, CoverageLevel level)
73     {
74         pango_coverage_set(nativePtr, index, level);
75     }
76 
77     void max (Coverage other)
78     {
79         pango_coverage_max(nativePtr, other.nativePtr);
80     }
81 
82     ubyte[] toBytes()
83     {
84         ubyte *arr;
85         int n_bytes;
86         pango_coverage_to_bytes(nativePtr, &arr, &n_bytes);
87         scope(exit) g_free(arr);
88 
89         if (!n_bytes) return [];
90 
91         ubyte[] res = new ubyte[n_bytes];
92         foreach(i; 0 .. n_bytes) {
93             res[i] = arr[i];
94         }
95         return res;
96     }
97 }