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.glyph; 7 8 import pango.utils; 9 import pango.font; 10 import pango.types; 11 import pango.item; 12 import pango.c.glyph; 13 14 import glib; 15 import gobject; 16 17 18 /* 1024ths of a device unit */ 19 /** 20 * GlyphUnit: 21 * 22 * The #PangoGlyphUnit type is used to store dimensions within 23 * Pango. Dimensions are stored in 1/%PANGO_SCALE of a device unit. 24 * (A device unit might be a pixel for screen display, or 25 * a point on a printer.) %PANGO_SCALE is currently 1024, and 26 * may change in the future (unlikely though), but you should not 27 * depend on its exact value. The PANGO_PIXELS() macro can be used 28 * to convert from glyph units into device units with correct rounding. 29 */ 30 alias GlyphUnit = PangoGlyphUnit; 31 32 /* Positioning information about a glyph 33 */ 34 /** 35 * PangoGlyphGeometry: 36 * @width: the logical width to use for the the character. 37 * @x_offset: horizontal offset from nominal character position. 38 * @y_offset: vertical offset from nominal character position. 39 * 40 * The #PangoGlyphGeometry structure contains width and positioning 41 * information for a single glyph. 42 */ 43 alias GlyphGeometry = PangoGlyphGeometry; 44 45 46 /* Visual attributes of a glyph 47 */ 48 /** 49 * PangoGlyphVisAttr: 50 * @is_cluster_start: set for the first logical glyph in each cluster. (Clusters 51 * are stored in visual order, within the cluster, glyphs 52 * are always ordered in logical order, since visual 53 * order is meaningless; that is, in Arabic text, accent glyphs 54 * follow the glyphs for the base character.) 55 * 56 * The PangoGlyphVisAttr is used to communicate information between 57 * the shaping phase and the rendering phase. More attributes may be 58 * added in the future. 59 */ 60 alias GlyphVisAttr = PangoGlyphVisAttr; 61 62 /* A single glyph 63 */ 64 /** 65 * PangoGlyphInfo: 66 * @glyph: the glyph itself. 67 * @geometry: the positional information about the glyph. 68 * @attr: the visual attributes of the glyph. 69 * 70 * The #PangoGlyphInfo structure represents a single glyph together with 71 * positioning information and visual attributes. 72 * It contains the following fields. 73 */ 74 alias GlyphInfo = PangoGlyphInfo; 75 76 /* A string of glyphs with positional information and visual attributes - 77 * ready for drawing 78 */ 79 /** 80 * PangoGlyphString: 81 * 82 * The #PangoGlyphString structure is used to store strings 83 * of glyphs with geometry and visual attribute information. 84 * The storage for the glyph information is owned 85 * by the structure which simplifies memory management. 86 */ 87 88 class GlyphString 89 { 90 mixin NativePtrHolder!(PangoGlyphString, pango_glyph_string_free); 91 92 package this(PangoGlyphString* ptr, Transfer transfer) { 93 initialize(ptr, transfer); 94 } 95 96 this() { 97 initialize(pango_glyph_string_new(), Transfer.Full); 98 } 99 100 void extents(Font font, out Rectangle inkRect, out Rectangle logicalRect) { 101 pango_glyph_string_extents(nativePtr, font.nativePtr, &inkRect, &logicalRect); 102 } 103 104 @property int width() { 105 return pango_glyph_string_get_width(nativePtr); 106 } 107 108 void extentsRange(int start, int end, Font font, out Rectangle inkRect, out Rectangle logicalRect) { 109 pango_glyph_string_extents_range(nativePtr, start, end, font.nativePtr, &inkRect, &logicalRect); 110 } 111 112 int[] logicalWidths(string text, int embeddingLevel) { 113 if (text.length == 0) return []; 114 int[] res = new int[g_utf8_strlen(text.ptr, text.length)]; 115 pango_glyph_string_get_logical_widths(nativePtr, cast(char*)text.ptr, cast(int)text.length, embeddingLevel, res.ptr); 116 return res; 117 } 118 119 int indexToX(string text, Analysis *analysis, int index, bool trailing) { 120 int res; 121 // const cast of text after checking in C source code that no modification 122 // is done on text (pointer is moved, dereferenced, but pointed-to data is not modified) 123 pango_glyph_string_index_to_x(nativePtr, cast(char*)text.ptr, cast(int)text.length, 124 &analysis.pangoStruct, index, trailing, &res); 125 return res; 126 } 127 128 int xToIndex(string text, Analysis *analysis, int xPos, out bool trailing) { 129 int ind; 130 int trail; 131 // const cast of text after checking in C source code that no modification 132 // is done on text (pointer is moved, dereferenced, but pointed-to data is not modified) 133 pango_glyph_string_x_to_index(nativePtr, cast(char*)text.ptr, cast(int)text.length, 134 &analysis.pangoStruct, xPos, &ind, &trail); 135 trailing = cast(bool)trail; 136 return ind; 137 } 138 139 140 /* Turn a string of characters into a string of glyphs 141 */ 142 static GlyphString shape(string text, const(Analysis)*analysis) { 143 auto str = new GlyphString(); 144 pango_shape(text.ptr, cast(int)text.length, &analysis.pangoStruct, str.nativePtr); 145 return str; 146 } 147 148 149 static GlyphString shapeFull(string text, string paragraph, const(Analysis)*analysis) { 150 auto str = new GlyphString(); 151 pango_shape_full(text.ptr, cast(int)text.length, 152 paragraph.ptr, cast(int)paragraph.length, &analysis.pangoStruct, str.nativePtr); 153 return str; 154 } 155 156 } 157 158 159 //GList *pango_reorder_items (GList *logical_items); 160