1 /**
2 Internationalized font and text drawing support.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.font;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.resource;
24 /**
25 Internationalized font and text drawing support.
26 
27 Font contains a Unicode-compatible character set, as well as the ability to draw it with variable width, ascent, descent and kerning. For creating fonts from TTF files (or other font formats), see the editor support for fonts.
28 $(B Note:) If a DynamicFont doesn't contain a character used in a string, the character in question will be replaced with codepoint `0xfffd` if it's available in the DynamicFont. If this replacement character isn't available in the DynamicFont, the character will be hidden without displaying any replacement character in the string.
29 $(B Note:) If a BitmapFont doesn't contain a character used in a string, the character in question will be hidden without displaying any replacement character in the string.
30 */
31 @GodotBaseClass struct Font
32 {
33 	package(godot) enum string _GODOT_internal_name = "Font";
34 public:
35 @nogc nothrow:
36 	union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; }
37 	alias _GODOT_base this;
38 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
39 	package(godot) __gshared bool _classBindingInitialized = false;
40 	package(godot) static struct GDNativeClassBinding
41 	{
42 		__gshared:
43 		@GodotName("draw") GodotMethod!(void, RID, Vector2, String, Color, long, Color) draw;
44 		@GodotName("draw_char") GodotMethod!(double, RID, Vector2, long, long, Color, bool) drawChar;
45 		@GodotName("get_ascent") GodotMethod!(double) getAscent;
46 		@GodotName("get_char_size") GodotMethod!(Vector2, long, long) getCharSize;
47 		@GodotName("get_descent") GodotMethod!(double) getDescent;
48 		@GodotName("get_height") GodotMethod!(double) getHeight;
49 		@GodotName("get_string_size") GodotMethod!(Vector2, String) getStringSize;
50 		@GodotName("get_wordwrap_string_size") GodotMethod!(Vector2, String, double) getWordwrapStringSize;
51 		@GodotName("has_outline") GodotMethod!(bool) hasOutline;
52 		@GodotName("is_distance_field_hint") GodotMethod!(bool) isDistanceFieldHint;
53 		@GodotName("update_changes") GodotMethod!(void) updateChanges;
54 	}
55 	/// 
56 	pragma(inline, true) bool opEquals(in Font other) const
57 	{ return _godot_object.ptr is other._godot_object.ptr; }
58 	/// 
59 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
60 	{ _godot_object.ptr = n; return null; }
61 	/// 
62 	pragma(inline, true) bool opEquals(typeof(null) n) const
63 	{ return _godot_object.ptr is n; }
64 	/// 
65 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
66 	mixin baseCasts;
67 	/// Construct a new instance of Font.
68 	/// Note: use `memnew!Font` instead.
69 	static Font _new()
70 	{
71 		static godot_class_constructor constructor;
72 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Font");
73 		if(constructor is null) return typeof(this).init;
74 		return cast(Font)(constructor());
75 	}
76 	@disable new(size_t s);
77 	/**
78 	Draw `string` into a canvas item using the font at a given position, with `modulate` color, and optionally clipping the width. `position` specifies the baseline, not the top. To draw from the top, $(I ascent) must be added to the Y axis.
79 	See also $(D CanvasItem.drawString).
80 	*/
81 	void draw(in RID canvas_item, in Vector2 position, in String string, in Color modulate = Color(1,1,1,1), in long clip_w = -1, in Color outline_modulate = Color(1,1,1,1)) const
82 	{
83 		checkClassBinding!(typeof(this))();
84 		ptrcall!(void)(GDNativeClassBinding.draw, _godot_object, canvas_item, position, string, modulate, clip_w, outline_modulate);
85 	}
86 	/**
87 	Draw character `char` into a canvas item using the font at a given position, with `modulate` color, and optionally kerning if `next` is passed. clipping the width. `position` specifies the baseline, not the top. To draw from the top, $(I ascent) must be added to the Y axis. The width used by the character is returned, making this function useful for drawing strings character by character.
88 	*/
89 	double drawChar(in RID canvas_item, in Vector2 position, in long _char, in long next = -1, in Color modulate = Color(1,1,1,1), in bool outline = false) const
90 	{
91 		checkClassBinding!(typeof(this))();
92 		return ptrcall!(double)(GDNativeClassBinding.drawChar, _godot_object, canvas_item, position, _char, next, modulate, outline);
93 	}
94 	/**
95 	Returns the font ascent (number of pixels above the baseline).
96 	*/
97 	double getAscent() const
98 	{
99 		checkClassBinding!(typeof(this))();
100 		return ptrcall!(double)(GDNativeClassBinding.getAscent, _godot_object);
101 	}
102 	/**
103 	Returns the size of a character, optionally taking kerning into account if the next character is provided. Note that the height returned is the font height (see $(D getHeight)) and has no relation to the glyph height.
104 	*/
105 	Vector2 getCharSize(in long _char, in long next = 0) const
106 	{
107 		checkClassBinding!(typeof(this))();
108 		return ptrcall!(Vector2)(GDNativeClassBinding.getCharSize, _godot_object, _char, next);
109 	}
110 	/**
111 	Returns the font descent (number of pixels below the baseline).
112 	*/
113 	double getDescent() const
114 	{
115 		checkClassBinding!(typeof(this))();
116 		return ptrcall!(double)(GDNativeClassBinding.getDescent, _godot_object);
117 	}
118 	/**
119 	Returns the total font height (ascent plus descent) in pixels.
120 	*/
121 	double getHeight() const
122 	{
123 		checkClassBinding!(typeof(this))();
124 		return ptrcall!(double)(GDNativeClassBinding.getHeight, _godot_object);
125 	}
126 	/**
127 	Returns the size of a string, taking kerning and advance into account. Note that the height returned is the font height (see $(D getHeight)) and has no relation to the string.
128 	*/
129 	Vector2 getStringSize(in String string) const
130 	{
131 		checkClassBinding!(typeof(this))();
132 		return ptrcall!(Vector2)(GDNativeClassBinding.getStringSize, _godot_object, string);
133 	}
134 	/**
135 	Returns the size that the string would have with word wrapping enabled with a fixed `width`.
136 	*/
137 	Vector2 getWordwrapStringSize(in String string, in double width) const
138 	{
139 		checkClassBinding!(typeof(this))();
140 		return ptrcall!(Vector2)(GDNativeClassBinding.getWordwrapStringSize, _godot_object, string, width);
141 	}
142 	/**
143 	Returns `true` if the font has an outline.
144 	*/
145 	bool hasOutline() const
146 	{
147 		checkClassBinding!(typeof(this))();
148 		return ptrcall!(bool)(GDNativeClassBinding.hasOutline, _godot_object);
149 	}
150 	/**
151 	
152 	*/
153 	bool isDistanceFieldHint() const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(bool)(GDNativeClassBinding.isDistanceFieldHint, _godot_object);
157 	}
158 	/**
159 	After editing a font (changing size, ascent, char rects, etc.). Call this function to propagate changes to controls that might use it.
160 	*/
161 	void updateChanges()
162 	{
163 		checkClassBinding!(typeof(this))();
164 		ptrcall!(void)(GDNativeClassBinding.updateChanges, _godot_object);
165 	}
166 }