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.fontset; 7 8 import pango.utils; 9 import pango.font; 10 import pango.c.font; 11 import pango.c.fontset; 12 13 import gobject; 14 import glib; 15 16 17 /** 18 * PangoFontset: 19 * 20 * A #PangoFontset represents a set of #PangoFont to use 21 * when rendering text. It is the result of resolving a 22 * #PangoFontDescription against a particular #PangoContext. 23 * It has operations for finding the component font for 24 * a particular Unicode character, and for finding a composite 25 * set of metrics for the entire fontset. 26 */ 27 class FontSet : D_GObject 28 { 29 mixin GObjectHolder!PangoFontset; 30 mixin FontFactoryHolder; 31 32 package this(PangoFontset *ptr, Transfer transfer) 33 { 34 super(cast(GObject*)ptr, transfer); 35 fontFactory = defaultFontFactory; 36 } 37 38 Font font(uint wc) { 39 return fontFactory.getFont(pango_fontset_get_font(nativePtr, wc), Transfer.Full); 40 } 41 42 @property FontMetrics metrics() { 43 return getDObject!FontMetrics(pango_fontset_get_metrics(nativePtr), Transfer.Full); 44 } 45 46 47 int opApply(int delegate(ref Font font) dg) 48 { 49 auto fd = ForeachData(dg, fontFactory); 50 pango_fontset_foreach(nativePtr, &foreachApplyCb, &fd); 51 return fd.res; 52 } 53 54 } 55 56 57 private 58 { 59 alias ForeachDelegate = int delegate(ref Font font); 60 61 struct ForeachData 62 { 63 int res = 0; 64 ForeachDelegate dg; 65 FontFactory fontFactory; 66 67 @disable this(); 68 69 this (ForeachDelegate dg, FontFactory fontFactory) { 70 this.dg = dg; 71 this.fontFactory = fontFactory; 72 } 73 } 74 75 extern (C) 76 private gboolean foreachApplyCb(PangoFontset* fontset, PangoFont *font, gpointer userData) 77 { 78 ForeachData *fd = cast(ForeachData*)userData; 79 auto dg = fd.dg; 80 auto f = fd.fontFactory.getFont(font, Transfer.None); 81 fd.res = dg(f); 82 if (fd.res) return TRUE; 83 else return FALSE; 84 } 85 86 }