From fc57073d1a1220e9dcbc1a1bbd68399414a18d39 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 11 Oct 2016 11:57:13 +0300 Subject: [PATCH] support getting list of font faces from fontManager --- README.md | 3 +++ src/dlangui/graphics/fonts.d | 13 +++++++++++++ src/dlangui/graphics/ftfonts.d | 19 +++++++++++++++++++ src/dlangui/platforms/windows/win32fonts.d | 21 ++++++++++++++++++++- src/dlangui/widgets/srcedit.d | 4 +++- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d272f0d..5658c5d5 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,14 @@ Currently implemented widgets: * CheckBox - check button with label * RadioButton - radio button with label * SwitchButton - a toggle switch button +* GroupBox - frame and caption for grouping other controls * EditLine - single line edit * EditBox - multiline editor * VSpacer - vertical spacer - just an empty widget with layoutHeight == FILL_PARENT, to fill vertical space in layouts * HSpacer - horizontal spacer - just an empty widget with layoutWidth == FILL_PARENT, to fill horizontal space in layouts * ScrollBar - scroll bar +* SliderWidget - slider +* ProgressBarWidget - progress bar * TabControl - tabs widget, allows to select one of tabs * TabHost - container for pages controlled by TabControl * TabWidget - combination of TabControl and TabHost diff --git a/src/dlangui/graphics/fonts.d b/src/dlangui/graphics/fonts.d index 5dc25de2..edad21c6 100644 --- a/src/dlangui/graphics/fonts.d +++ b/src/dlangui/graphics/fonts.d @@ -652,6 +652,14 @@ enum HintingMode : int { Light // 3 } +/// font face properties item +struct FontFaceProps { + /// font face name + string face; + /// font family + FontFamily family; +} + /// Access points to fonts. class FontManager { protected static __gshared FontManager _instance; @@ -676,6 +684,11 @@ class FontManager { /// get font instance best matched specified parameters abstract ref FontRef getFont(int size, int weight, bool italic, FontFamily family, string face); + /// override to return list of font faces available + FontFaceProps[] getFaces() { + return null; + } + /// clear usage flags for all entries -- for cleanup of unused fonts abstract void checkpoint(); diff --git a/src/dlangui/graphics/ftfonts.d b/src/dlangui/graphics/ftfonts.d index 8cfe3c98..e24ab228 100644 --- a/src/dlangui/graphics/ftfonts.d +++ b/src/dlangui/graphics/ftfonts.d @@ -495,6 +495,25 @@ class FreeTypeFontManager : FontManager { return null; } + /// override to return list of font faces available + override FontFaceProps[] getFaces() { + FontFaceProps[] res; + for (int i = 0; i < _fontFiles.length; i++) { + FontFaceProps item = FontFaceProps(_fontFiles[i].def.face, _fontFiles[i].def.family); + bool found = false; + for (int j = 0; j < res.length; j++) { + if (res[j].face == item.face) { + found = true; + break; + } + } + if (!found) + res ~= item; + } + return res; + } + + private static int faceMatch(string requested, string existing) { if (!requested.icmp("Arial")) { if (!existing.icmp("DejaVu Sans")) { diff --git a/src/dlangui/platforms/windows/win32fonts.d b/src/dlangui/platforms/windows/win32fonts.d index 0b197f61..82f68cea 100644 --- a/src/dlangui/platforms/windows/win32fonts.d +++ b/src/dlangui/platforms/windows/win32fonts.d @@ -496,7 +496,26 @@ class Win32FontManager : FontManager { private FontList _activeFonts; private FontDef[] _fontFaces; private FontDef*[string] _faceByName; - + + /// override to return list of font faces available + override FontFaceProps[] getFaces() { + FontFaceProps[] res; + for (int i = 0; i < _fontFaces.length; i++) { + FontFaceProps item = FontFaceProps(_fontFaces[i].face, _fontFaces[i].family); + bool found = false; + for (int j = 0; j < res.length; j++) { + if (res[j].face == item.face) { + found = true; + break; + } + } + if (!found) + res ~= item; + } + return res; + } + + /// initialize in constructor this() { debug Log.i("Creating Win32FontManager"); diff --git a/src/dlangui/widgets/srcedit.d b/src/dlangui/widgets/srcedit.d index d74e3ea9..0e5f36a8 100644 --- a/src/dlangui/widgets/srcedit.d +++ b/src/dlangui/widgets/srcedit.d @@ -22,10 +22,12 @@ import dlangui.graphics.fonts; import dlangui.widgets.editors; import dlangui.widgets.styles; +enum DEFAULT_SOURCE_EDIT_FONT_FACES = "Menlo,Consolas,DejaVuSansMono,DejaVu Sans Mono,Liberation Mono,Lucida Sans Typewriter,Courier New,Lucida Console"; + class SourceEdit : EditBox { this(string ID) { super(ID); - fontFace = "Menlo,Consolas,DejaVuSansMono,DejaVu Sans Mono,Liberation Mono,Lucida Sans Typewriter,Courier New,Lucida Console"; + fontFace = DEFAULT_SOURCE_EDIT_FONT_FACES; //fontFace = "Consolas,Lucida Console,Courier New"; fontFamily = FontFamily.MonoSpace; fontSize = makePointSize(10);