From d7ae4a62645d369fbd6b8b5f3f0e12ee86536da1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 20 Nov 2006 20:45:57 +0000 Subject: [PATCH] moved wxMGL's font management code to common so that it can be reused by wxDFB; implemented wxDFB part git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43550 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 81 +++++++- build/bakefiles/files.bkl | 5 +- configure | 26 +-- configure.in | 2 +- include/wx/dfb/chkconf.h | 4 + include/wx/dfb/dc.h | 2 + include/wx/dfb/font.h | 6 +- include/wx/dfb/private/fontmgr.h | 83 ++++++++ include/wx/dfb/wrapdfb.h | 1 + include/wx/fontutil.h | 8 - include/wx/mgl/font.h | 4 + include/wx/mgl/fontutil.h | 124 ----------- include/wx/mgl/private/fontmgr.h | 77 +++++++ include/wx/private/fontmgr.h | 255 +++++++++++++++++++++++ src/common/fontmgrcmn.cpp | 345 +++++++++++++++++++++++++++++++ src/dfb/app.cpp | 3 + src/dfb/dc.cpp | 21 +- src/dfb/fontmgr.cpp | 217 +++++++++++++++++++ src/mgl/app.cpp | 10 +- src/mgl/fontenum.cpp | 11 +- src/mgl/fontmgr.cpp | 169 +++++++++++++++ src/mgl/fontutil.cpp | 306 +-------------------------- 22 files changed, 1293 insertions(+), 467 deletions(-) create mode 100644 include/wx/dfb/private/fontmgr.h delete mode 100644 include/wx/mgl/fontutil.h create mode 100644 include/wx/mgl/private/fontmgr.h create mode 100644 include/wx/private/fontmgr.h create mode 100644 src/common/fontmgrcmn.cpp create mode 100644 src/dfb/fontmgr.cpp create mode 100644 src/mgl/fontmgr.cpp diff --git a/Makefile.in b/Makefile.in index 288153cdca..e5156e84d5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1845,7 +1845,6 @@ COND_TOOLKIT_MGL_LOWLEVEL_HDR = \ wx/mgl/dcmemory.h \ wx/mgl/dcscreen.h \ wx/mgl/font.h \ - wx/mgl/fontutil.h \ wx/mgl/palette.h \ wx/mgl/pen.h \ wx/mgl/popupwin.h \ @@ -3716,6 +3715,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS = \ @COND_TOOLKIT_COCOA@ monodll_gsockosx.o monodll_hid.o monodll_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \ + monodll_fontmgrcmn.o \ monodll_caret.o \ monodll_colour.o \ monodll_icon.o \ @@ -3733,6 +3733,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \ monodll_evtloop.o \ monodll_font.o \ monodll_fontenum.o \ + monodll_fontmgr.o \ monodll_overlay.o \ monodll_pen.o \ monodll_region.o \ @@ -3824,6 +3825,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS = \ @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__LOWLEVEL_SRC_OBJECTS = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS) @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS = $(__MAC_LOWLEVEL_SRC_OBJECTS) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS = \ + monodll_fontmgrcmn.o \ monodll_caret.o \ monodll_colour.o \ monodll_icon.o \ @@ -3844,6 +3846,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS = \ monodll_evtloop.o \ monodll_font.o \ monodll_fontenum.o \ + monodll_fontmgr.o \ monodll_fontutil.o \ monodll_palette.o \ monodll_pen.o \ @@ -4542,6 +4545,7 @@ COND_TOOLKIT_WINCE___GUI_SRC_OBJECTS = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_1 = \ @COND_TOOLKIT_COCOA@ monodll_gsockosx.o monodll_hid.o monodll_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_1 = \ + monodll_fontmgrcmn.o \ monodll_caret.o \ monodll_colour.o \ monodll_icon.o \ @@ -4559,6 +4563,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_1 = \ monodll_evtloop.o \ monodll_font.o \ monodll_fontenum.o \ + monodll_fontmgr.o \ monodll_overlay.o \ monodll_pen.o \ monodll_region.o \ @@ -4650,6 +4655,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_1 = \ @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@__LOWLEVEL_SRC_OBJECTS_1 = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_1) @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_1 = $(__MAC_LOWLEVEL_SRC_OBJECTS) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_1 = \ + monodll_fontmgrcmn.o \ monodll_caret.o \ monodll_colour.o \ monodll_icon.o \ @@ -4670,6 +4676,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_1 = \ monodll_evtloop.o \ monodll_font.o \ monodll_fontenum.o \ + monodll_fontmgr.o \ monodll_fontutil.o \ monodll_palette.o \ monodll_pen.o \ @@ -5480,6 +5487,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_1 = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_2 = \ @COND_TOOLKIT_COCOA@ monolib_gsockosx.o monolib_hid.o monolib_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \ + monolib_fontmgrcmn.o \ monolib_caret.o \ monolib_colour.o \ monolib_icon.o \ @@ -5497,6 +5505,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \ monolib_evtloop.o \ monolib_font.o \ monolib_fontenum.o \ + monolib_fontmgr.o \ monolib_overlay.o \ monolib_pen.o \ monolib_region.o \ @@ -5589,6 +5598,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_2 = \ @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_2 = \ @COND_TOOLKIT_MAC@ $(__MAC_LOWLEVEL_SRC_OBJECTS_0) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_2 = \ + monolib_fontmgrcmn.o \ monolib_caret.o \ monolib_colour.o \ monolib_icon.o \ @@ -5609,6 +5619,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_2 = \ monolib_evtloop.o \ monolib_font.o \ monolib_fontenum.o \ + monolib_fontmgr.o \ monolib_fontutil.o \ monolib_palette.o \ monolib_pen.o \ @@ -6307,6 +6318,7 @@ COND_TOOLKIT_WINCE___GUI_SRC_OBJECTS_1 = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_3 = \ @COND_TOOLKIT_COCOA@ monolib_gsockosx.o monolib_hid.o monolib_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_3 = \ + monolib_fontmgrcmn.o \ monolib_caret.o \ monolib_colour.o \ monolib_icon.o \ @@ -6324,6 +6336,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_3 = \ monolib_evtloop.o \ monolib_font.o \ monolib_fontenum.o \ + monolib_fontmgr.o \ monolib_overlay.o \ monolib_pen.o \ monolib_region.o \ @@ -6416,6 +6429,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_3 = \ @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_3 = \ @COND_TOOLKIT_MAC@ $(__MAC_LOWLEVEL_SRC_OBJECTS_0) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_3 = \ + monolib_fontmgrcmn.o \ monolib_caret.o \ monolib_colour.o \ monolib_icon.o \ @@ -6436,6 +6450,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_3 = \ monolib_evtloop.o \ monolib_font.o \ monolib_fontenum.o \ + monolib_fontmgr.o \ monolib_fontutil.o \ monolib_palette.o \ monolib_pen.o \ @@ -7474,6 +7489,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_2 = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_4 = \ @COND_TOOLKIT_COCOA@ coredll_gsockosx.o coredll_hid.o coredll_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \ + coredll_fontmgrcmn.o \ coredll_caret.o \ coredll_colour.o \ coredll_icon.o \ @@ -7491,6 +7507,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \ coredll_evtloop.o \ coredll_font.o \ coredll_fontenum.o \ + coredll_fontmgr.o \ coredll_overlay.o \ coredll_pen.o \ coredll_region.o \ @@ -7583,6 +7600,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_4 = \ @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_4 = \ @COND_TOOLKIT_MAC@ $(__MAC_LOWLEVEL_SRC_OBJECTS_8) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_4 = \ + coredll_fontmgrcmn.o \ coredll_caret.o \ coredll_colour.o \ coredll_icon.o \ @@ -7603,6 +7621,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_4 = \ coredll_evtloop.o \ coredll_font.o \ coredll_fontenum.o \ + coredll_fontmgr.o \ coredll_fontutil.o \ coredll_palette.o \ coredll_pen.o \ @@ -8301,6 +8320,7 @@ COND_TOOLKIT_WINCE___GUI_SRC_OBJECTS_2 = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_5 = \ @COND_TOOLKIT_COCOA@ coredll_gsockosx.o coredll_hid.o coredll_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_5 = \ + coredll_fontmgrcmn.o \ coredll_caret.o \ coredll_colour.o \ coredll_icon.o \ @@ -8318,6 +8338,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_5 = \ coredll_evtloop.o \ coredll_font.o \ coredll_fontenum.o \ + coredll_fontmgr.o \ coredll_overlay.o \ coredll_pen.o \ coredll_region.o \ @@ -8410,6 +8431,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_5 = \ @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_5 = \ @COND_TOOLKIT_MAC@ $(__MAC_LOWLEVEL_SRC_OBJECTS_8) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_5 = \ + coredll_fontmgrcmn.o \ coredll_caret.o \ coredll_colour.o \ coredll_icon.o \ @@ -8430,6 +8452,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_5 = \ coredll_evtloop.o \ coredll_font.o \ coredll_fontenum.o \ + coredll_fontmgr.o \ coredll_fontutil.o \ coredll_palette.o \ coredll_pen.o \ @@ -8912,6 +8935,7 @@ COND_USE_GUI_1_WXUNIV_1___CORE_SRC_OBJECTS_3 = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_6 = \ @COND_TOOLKIT_COCOA@ corelib_gsockosx.o corelib_hid.o corelib_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \ + corelib_fontmgrcmn.o \ corelib_caret.o \ corelib_colour.o \ corelib_icon.o \ @@ -8929,6 +8953,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \ corelib_evtloop.o \ corelib_font.o \ corelib_fontenum.o \ + corelib_fontmgr.o \ corelib_overlay.o \ corelib_pen.o \ corelib_region.o \ @@ -9021,6 +9046,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_6 = \ @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_6 = \ @COND_TOOLKIT_MAC@ $(__MAC_LOWLEVEL_SRC_OBJECTS_9) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_6 = \ + corelib_fontmgrcmn.o \ corelib_caret.o \ corelib_colour.o \ corelib_icon.o \ @@ -9041,6 +9067,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_6 = \ corelib_evtloop.o \ corelib_font.o \ corelib_fontenum.o \ + corelib_fontmgr.o \ corelib_fontutil.o \ corelib_palette.o \ corelib_pen.o \ @@ -9739,6 +9766,7 @@ COND_TOOLKIT_WINCE___GUI_SRC_OBJECTS_3 = \ @COND_TOOLKIT_COCOA@__LOWLEVEL_SRC_OBJECTS_7 = \ @COND_TOOLKIT_COCOA@ corelib_gsockosx.o corelib_hid.o corelib_utilsexc_cf.o COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_7 = \ + corelib_fontmgrcmn.o \ corelib_caret.o \ corelib_colour.o \ corelib_icon.o \ @@ -9756,6 +9784,7 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_7 = \ corelib_evtloop.o \ corelib_font.o \ corelib_fontenum.o \ + corelib_fontmgr.o \ corelib_overlay.o \ corelib_pen.o \ corelib_region.o \ @@ -9848,6 +9877,7 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2___LOWLEVEL_SRC_OBJECTS_7 = \ @COND_TOOLKIT_MAC@__LOWLEVEL_SRC_OBJECTS_7 = \ @COND_TOOLKIT_MAC@ $(__MAC_LOWLEVEL_SRC_OBJECTS_9) COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_7 = \ + corelib_fontmgrcmn.o \ corelib_caret.o \ corelib_colour.o \ corelib_icon.o \ @@ -9868,6 +9898,7 @@ COND_TOOLKIT_MGL___LOWLEVEL_SRC_OBJECTS_7 = \ corelib_evtloop.o \ corelib_font.o \ corelib_fontenum.o \ + corelib_fontmgr.o \ corelib_fontutil.o \ corelib_palette.o \ corelib_pen.o \ @@ -14747,6 +14778,12 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@monodll_reparent.o: $(srcdir)/src/x11/reparent.cpp $(MONODLL_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/x11/reparent.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@monodll_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@monodll_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + @COND_TOOLKIT_MGL_USE_GUI_1@monodll_mask.o: $(srcdir)/src/generic/mask.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/mask.cpp @@ -14756,6 +14793,12 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@monodll_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@monodll_fontmgr.o: $(srcdir)/src/mgl/fontmgr.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mgl/fontmgr.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@monodll_fontmgr.o: $(srcdir)/src/dfb/fontmgr.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/dfb/fontmgr.cpp + @COND_TOOLKIT_DFB_USE_GUI_1@monodll_overlay.o: $(srcdir)/src/dfb/overlay.cpp $(MONODLL_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/dfb/overlay.cpp @@ -18839,6 +18882,12 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@monolib_reparent.o: $(srcdir)/src/x11/reparent.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/x11/reparent.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@monolib_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@monolib_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + @COND_TOOLKIT_MGL_USE_GUI_1@monolib_mask.o: $(srcdir)/src/generic/mask.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/mask.cpp @@ -18848,6 +18897,12 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@monolib_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@monolib_fontmgr.o: $(srcdir)/src/mgl/fontmgr.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mgl/fontmgr.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@monolib_fontmgr.o: $(srcdir)/src/dfb/fontmgr.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/dfb/fontmgr.cpp + @COND_TOOLKIT_DFB_USE_GUI_1@monolib_overlay.o: $(srcdir)/src/dfb/overlay.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/dfb/overlay.cpp @@ -23312,6 +23367,12 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@coredll_reparent.o: $(srcdir)/src/x11/reparent.cpp $(COREDLL_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/x11/reparent.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@coredll_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@coredll_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + @COND_TOOLKIT_MGL_USE_GUI_1@coredll_mask.o: $(srcdir)/src/generic/mask.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/mask.cpp @@ -23321,6 +23382,12 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@coredll_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@coredll_fontmgr.o: $(srcdir)/src/mgl/fontmgr.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mgl/fontmgr.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@coredll_fontmgr.o: $(srcdir)/src/dfb/fontmgr.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/dfb/fontmgr.cpp + @COND_TOOLKIT_DFB_USE_GUI_1@coredll_overlay.o: $(srcdir)/src/dfb/overlay.cpp $(COREDLL_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/dfb/overlay.cpp @@ -26240,6 +26307,12 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@corelib_reparent.o: $(srcdir)/src/x11/reparent.cpp $(CORELIB_ODEP) @COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/x11/reparent.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@corelib_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@corelib_fontmgrcmn.o: $(srcdir)/src/common/fontmgrcmn.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/fontmgrcmn.cpp + @COND_TOOLKIT_MGL_USE_GUI_1@corelib_mask.o: $(srcdir)/src/generic/mask.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/mask.cpp @@ -26249,6 +26322,12 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@corelib_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp +@COND_TOOLKIT_MGL_USE_GUI_1@corelib_fontmgr.o: $(srcdir)/src/mgl/fontmgr.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mgl/fontmgr.cpp + +@COND_TOOLKIT_DFB_USE_GUI_1@corelib_fontmgr.o: $(srcdir)/src/dfb/fontmgr.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/dfb/fontmgr.cpp + @COND_TOOLKIT_DFB_USE_GUI_1@corelib_overlay.o: $(srcdir)/src/dfb/overlay.cpp $(CORELIB_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/dfb/overlay.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 2747d2d9da..7db951eec3 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1747,6 +1747,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! + src/common/fontmgrcmn.cpp src/generic/caret.cpp src/generic/colour.cpp src/generic/icon.cpp @@ -1767,6 +1768,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/mgl/evtloop.cpp src/mgl/font.cpp src/mgl/fontenum.cpp + src/mgl/fontmgr.cpp src/mgl/fontutil.cpp src/mgl/palette.cpp src/mgl/pen.cpp @@ -1794,7 +1796,6 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/mgl/dcmemory.h wx/mgl/dcscreen.h wx/mgl/font.h - wx/mgl/fontutil.h wx/mgl/palette.h wx/mgl/pen.h wx/mgl/popupwin.h @@ -1810,6 +1811,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! + src/common/fontmgrcmn.cpp src/generic/caret.cpp src/generic/colour.cpp src/generic/icon.cpp @@ -1828,6 +1830,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/dfb/evtloop.cpp src/dfb/font.cpp src/dfb/fontenum.cpp + src/dfb/fontmgr.cpp src/dfb/overlay.cpp src/dfb/pen.cpp src/dfb/region.cpp diff --git a/configure b/configure index 25ab02759f..ec829df8fe 100755 --- a/configure +++ b/configure @@ -12560,7 +12560,7 @@ echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 GCC=`test $ac_compiler_gnu = yes && echo yes` ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" +CFLAGS="$CFLAGS -g" echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 if test "${ac_cv_prog_cc_g+set}" = set; then @@ -13032,7 +13032,7 @@ fi unset ac_cv_prog_cc_g ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" +CFLAGS="$CFLAGS -g" echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 if test "${ac_cv_prog_cc_g+set}" = set; then @@ -14197,9 +14197,9 @@ if test "$ac_test_CXXFLAGS" = set; then CXXFLAGS=$ac_save_CXXFLAGS elif test $ac_cv_prog_cxx_g = yes; then if test "$GXX" = yes; then - CXXFLAGS="-g -O2" + CXXFLAGS="$CXXFLAGS -g -O2" else - CXXFLAGS="-g" + CXXFLAGS="$CXXFLAGS -g" fi else if test "$GXX" = yes; then @@ -14462,7 +14462,7 @@ fi unset ac_cv_prog_cc_g ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" +CFLAGS="$CFLAGS -g" echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 if test "${ac_cv_prog_cc_g+set}" = set; then @@ -29048,12 +29048,12 @@ if test -n "$PKG_CONFIG"; then pkg_cv_DIRECTFB_CFLAGS="$DIRECTFB_CFLAGS" else if test -n "$PKG_CONFIG" && \ - { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"directfb >= 0.9.22\"") >&5 - ($PKG_CONFIG --exists --print-errors "directfb >= 0.9.22") 2>&5 + { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"directfb >= 0.9.23\"") >&5 + ($PKG_CONFIG --exists --print-errors "directfb >= 0.9.23") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; then - pkg_cv_DIRECTFB_CFLAGS=`$PKG_CONFIG --cflags "directfb >= 0.9.22" 2>/dev/null` + pkg_cv_DIRECTFB_CFLAGS=`$PKG_CONFIG --cflags "directfb >= 0.9.23" 2>/dev/null` else pkg_failed=yes fi @@ -29066,12 +29066,12 @@ if test -n "$PKG_CONFIG"; then pkg_cv_DIRECTFB_LIBS="$DIRECTFB_LIBS" else if test -n "$PKG_CONFIG" && \ - { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"directfb >= 0.9.22\"") >&5 - ($PKG_CONFIG --exists --print-errors "directfb >= 0.9.22") 2>&5 + { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"directfb >= 0.9.23\"") >&5 + ($PKG_CONFIG --exists --print-errors "directfb >= 0.9.23") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; then - pkg_cv_DIRECTFB_LIBS=`$PKG_CONFIG --libs "directfb >= 0.9.22" 2>/dev/null` + pkg_cv_DIRECTFB_LIBS=`$PKG_CONFIG --libs "directfb >= 0.9.23" 2>/dev/null` else pkg_failed=yes fi @@ -29090,9 +29090,9 @@ else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then - DIRECTFB_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "directfb >= 0.9.22"` + DIRECTFB_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "directfb >= 0.9.23"` else - DIRECTFB_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "directfb >= 0.9.22"` + DIRECTFB_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "directfb >= 0.9.23"` fi # Put the nasty error message in config.log where it belongs echo "$DIRECTFB_PKG_ERRORS" >&5 diff --git a/configure.in b/configure.in index 3b119308e4..8a5165513e 100644 --- a/configure.in +++ b/configure.in @@ -3282,7 +3282,7 @@ libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config PKG_PROG_PKG_CONFIG() PKG_CHECK_MODULES(DIRECTFB, - [directfb >= 0.9.22], + [directfb >= 0.9.23], [ wxUSE_UNIVERSAL="yes" TOOLKIT_INCLUDE="$DIRECTFB_CFLAGS" diff --git a/include/wx/dfb/chkconf.h b/include/wx/dfb/chkconf.h index 860ea06cee..290fb62220 100644 --- a/include/wx/dfb/chkconf.h +++ b/include/wx/dfb/chkconf.h @@ -17,4 +17,8 @@ # error "wxDirectFB cannot be built without wxUniversal" #endif +#if !wxUSE_CONFIG +# error "wxFileConfig is required by wxDFB port" +#endif + #endif /* _WX_DFB_CHKCONF_H_ */ diff --git a/include/wx/dfb/dc.h b/include/wx/dfb/dc.h index b5cfff51d9..7adfd288bb 100644 --- a/include/wx/dfb/dc.h +++ b/include/wx/dfb/dc.h @@ -169,6 +169,8 @@ protected: int fillStyle = wxODDEVEN_RULE); // implementation from now on: +protected: + wxIDirectFBFontPtr GetCurrentFont() const; private: // Unified implementation of DrawIcon, DrawBitmap and Blit: diff --git a/include/wx/dfb/font.h b/include/wx/dfb/font.h index b9d54786ac..d408ea043b 100644 --- a/include/wx/dfb/font.h +++ b/include/wx/dfb/font.h @@ -63,8 +63,12 @@ public: virtual void SetUnderlined(bool underlined); virtual void SetEncoding(wxFontEncoding encoding); + // Unofficial API, don't use + virtual void SetNoAntiAliasing(bool no = true); + virtual bool GetNoAntiAliasing() const; + // implementation from now on: - wxIDirectFBFontPtr GetDirectFBFont() const; + wxIDirectFBFontPtr GetDirectFBFont(bool antialiased) const; protected: // ref counting code diff --git a/include/wx/dfb/private/fontmgr.h b/include/wx/dfb/private/fontmgr.h new file mode 100644 index 0000000000..c3bd74e73f --- /dev/null +++ b/include/wx/dfb/private/fontmgr.h @@ -0,0 +1,83 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/dfb/private/fontmgr.h +// Purpose: font management for wxDFB +// Author: Vaclav Slavik +// Created: 2006-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) +// (c) 2006 REA Elektronik GmbH +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_DFB_PRIVATE_FONTMGR_H_ +#define _WX_DFB_PRIVATE_FONTMGR_H_ + +#include "wx/dfb/wrapdfb.h" + +class wxFileConfig; + +class wxFontInstance : public wxFontInstanceBase +{ +public: + wxFontInstance(float ptSize, bool aa, const wxString& filename); + + wxIDirectFBFontPtr GetDirectFBFont() const { return m_font; } + +private: + wxIDirectFBFontPtr m_font; +}; + +class wxFontFace : public wxFontFaceBase +{ +public: + wxFontFace(const wxString& filename) : m_fileName(filename) {} + +protected: + wxFontInstance *CreateFontInstance(float ptSize, bool aa); + +private: + wxString m_fileName; +}; + +class wxFontBundle : public wxFontBundleBase +{ +public: + wxFontBundle(const wxString& name, + const wxString& fileRegular, + const wxString& fileBold, + const wxString& fileItalic, + const wxString& fileBoldItalic, + bool isFixed); + + /// Returns name of the family + virtual wxString GetName() const { return m_name; } + + virtual bool IsFixed() const { return m_isFixed; } + +private: + wxString m_name; + bool m_isFixed; +}; + +class wxFontsManager : public wxFontsManagerBase +{ +public: + wxFontsManager() { AddAllFonts(); } + + virtual wxString GetDefaultFacename(wxFontFamily family) const + { + return m_defaultFacenames[family]; + } + +private: + // adds all fonts using AddBundle() + void AddAllFonts(); + void AddFont(const wxString& dir, const wxString& name, wxFileConfig& cfg); + void SetDefaultFonts(wxFileConfig& cfg); + +private: + // default facenames + wxString m_defaultFacenames[wxFONTFAMILY_MAX]; +}; + +#endif // _WX_DFB_PRIVATE_FONTMGR_H_ diff --git a/include/wx/dfb/wrapdfb.h b/include/wx/dfb/wrapdfb.h index 3e80393326..c08123d103 100644 --- a/include/wx/dfb/wrapdfb.h +++ b/include/wx/dfb/wrapdfb.h @@ -17,6 +17,7 @@ wxDFB_DECLARE_INTERFACE(IDirectFB); wxDFB_DECLARE_INTERFACE(IDirectFBDisplayLayer); +wxDFB_DECLARE_INTERFACE(IDirectFBFont); wxDFB_DECLARE_INTERFACE(IDirectFBWindow); wxDFB_DECLARE_INTERFACE(IDirectFBSurface); wxDFB_DECLARE_INTERFACE(IDirectFBPalette); diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index e07b2eafe8..12798501f0 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -239,12 +239,4 @@ extern bool wxTestFontEncoding(const wxNativeEncodingInfo& info); #include "wx/unix/fontutil.h" #endif // X || GDK -// ---------------------------------------------------------------------------- -// font-related functions (MGL) -// ---------------------------------------------------------------------------- - -#ifdef __WXMGL__ - #include "wx/mgl/fontutil.h" -#endif // __WXMGL__ - #endif // _WX_FONTUTIL_H_ diff --git a/include/wx/mgl/font.h b/include/wx/mgl/font.h index 75fd7e9aaa..b33e7341c5 100644 --- a/include/wx/mgl/font.h +++ b/include/wx/mgl/font.h @@ -79,6 +79,10 @@ public: virtual void SetUnderlined(bool underlined); virtual void SetEncoding(wxFontEncoding encoding); + // Unofficial API, don't use + virtual void SetNoAntiAliasing(bool no = true); + virtual bool GetNoAntiAliasing() const; + struct font_t *GetMGLfont_t(float scale, bool antialiased); protected: diff --git a/include/wx/mgl/fontutil.h b/include/wx/mgl/fontutil.h deleted file mode 100644 index dd286a712c..0000000000 --- a/include/wx/mgl/fontutil.h +++ /dev/null @@ -1,124 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wx/mgl/fontutil.h -// Purpose: font-related helper functions for MGL -// Author: Vaclav Slavik -// Created: 2001/05/01 -// RCS-ID: $Id$ -// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_MGL_FONTUTIL_H_ -#define _WX_MGL_FONTUTIL_H_ - -#include "wx/list.h" - -struct font_info_t; -struct font_lib_t; -struct font_t; - -class wxMGLFontInstance; -class wxMGLFontInstanceList; -class wxMGLFontLibrary; -class wxMGLFontFamily; - -enum -{ - wxFONTFACE_REGULAR = 0, - wxFONTFACE_ITALIC = 1, - wxFONTFACE_BOLD = 2, // = (regular | bold) - wxFONTFACE_BOLD_ITALIC = 3, // = (italic | bold) - - wxFONTFACE_MAX -}; - -// structure representing particular loaded font instance: -class wxMGLFontInstance -{ -public: - wxMGLFontInstance(wxMGLFontLibrary *fontLib, float pt, bool slant, bool aa); - ~wxMGLFontInstance(); - - struct font_t *GetMGLfont_t() const { return m_font; } - - float GetPt() const { return m_pt; } - bool GetSlant() const { return m_slant; } - bool GetAA() const { return m_aa; } - -private: - wxMGLFontLibrary *m_fontLib; - font_t *m_font; - float m_pt; - bool m_slant; - bool m_aa; -}; - -// structure representing loaded font library: -class wxMGLFontLibrary -{ -public: - wxMGLFontLibrary(const wxString& filename, int type, wxMGLFontFamily *parentFamily); - ~wxMGLFontLibrary(); - - wxMGLFontInstance *GetFontInstance(wxFont *font, float scale, bool aa); - wxMGLFontFamily *GetFamily() const { return m_family; } - - void IncRef(); - void DecRef(); - - struct font_lib_t *GetMGLfont_lib_t() const { return m_fontLib; } - -private: - font_lib_t *m_fontLib; - int m_type; - wxString m_fileName; - size_t m_refs; - wxMGLFontInstanceList *m_instances; - wxMGLFontFamily *m_family; -}; - -// structure representing native MGL font family -class wxMGLFontFamily : public wxObject -{ -public: - wxMGLFontFamily(const font_info_t *info); - virtual ~wxMGLFontFamily(); - - wxString GetName() const { return m_name; } - const font_info_t *GetInfo() const { return m_fontInfo; } - - bool HasFace(int type) const; - wxMGLFontLibrary *GetLibrary(int type) const - { return m_fontLibs[type]; } - -private: - wxString m_name; - const font_info_t *m_fontInfo; - wxMGLFontLibrary *m_fontLibs[wxFONTFACE_MAX]; -}; - -WX_DECLARE_LIST(wxMGLFontFamily, wxMGLFontFamilyList); - -class wxFontsManager -{ - public: - wxFontsManager(); - ~wxFontsManager(); - - void AddFamily(const font_info_t *info); - - // return info about font with given name: - wxMGLFontFamily *GetFamily(const wxString& name) const; - // return list of all families - wxMGLFontFamilyList *GetFamilyList() { return m_list; } - - wxMGLFontLibrary *GetFontLibrary(wxFont *font); - - private: - wxHashTable *m_hash; - wxMGLFontFamilyList *m_list; -}; - -extern wxFontsManager *wxTheFontsManager; - -#endif // _WX_MGL_FONTUTIL_H_ diff --git a/include/wx/mgl/private/fontmgr.h b/include/wx/mgl/private/fontmgr.h new file mode 100644 index 0000000000..2e24ffe5fd --- /dev/null +++ b/include/wx/mgl/private/fontmgr.h @@ -0,0 +1,77 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/mgl/private/fontmgr.h +// Purpose: font management for MGL +// Author: Vaclav Slavik +// Created: 2006-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MGL_PRIVATE_FONTMGR_H_ +#define _WX_MGL_PRIVATE_FONTMGR_H_ + +struct font_info_t; +struct font_lib_t; +struct font_t; + +class wxFontInstance : public wxFontInstanceBase +{ +public: + wxFontInstance(float ptSize, bool aa, font_lib_t *fontLib); + virtual ~wxFontInstance(); + + struct font_t *GetMGLfont_t() const { return m_font; } + +private: + font_t *m_font; +}; + +class wxFontFace : public wxFontFaceBase +{ +public: + wxFontFace(const wxString& filename) + : m_fontLib(NULL), m_fileName(filename) {} + + virtual void Acquire(); + virtual void Release(); + + virtual wxFontInstance *GetFontInstance(float ptSize, bool aa); + +protected: + wxFontInstance *CreateFontInstance(float ptSize, bool aa); + +private: + font_lib_t *m_fontLib; + wxString m_fileName; +}; + +class wxFontBundle : public wxFontBundleBase +{ +public: + wxFontBundle(const font_info_t *fontInfo); + + virtual wxString GetName() const + { return wxString::FromAscii(m_fontInfo->familyName); } + + virtual bool IsFixed() const { return m_fontInfo->isFixed; } + + const font_info_t *GetInfo() const { return m_fontInfo; } + +private: + const font_info_t *m_fontInfo; +}; + +class wxFontsManager : public wxFontsManagerBase +{ +public: + wxFontsManager() { AddAllFonts(); } + + virtual wxString GetDefaultFacename(wxFontFamily family) const; + +private: + // adds all fonts using AddBundle() + void AddAllFonts(); +}; + +#endif // _WX_MGL_PRIVATE_FONTMGR_H_ diff --git a/include/wx/private/fontmgr.h b/include/wx/private/fontmgr.h new file mode 100644 index 0000000000..d886739ae6 --- /dev/null +++ b/include/wx/private/fontmgr.h @@ -0,0 +1,255 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/private/fontmgr.h +// Purpose: font management for ports that don't have their own +// Author: Vaclav Slavik +// Created: 2006-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) +// (c) 2006 REA Elektronik GmbH +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_PRIVATE_FONTMGR_H_ +#define _WX_PRIVATE_FONTMGR_H_ + +#include "wx/list.h" +#include "wx/fontutil.h" + +class wxFontsManager; +class wxFontInstance; +class wxFontInstanceList; +class wxFontFace; +class wxFontBundle; +class wxFontBundleHash; +class wxFontMgrFontRefData; + +WX_DECLARE_LIST(wxFontBundle, wxFontBundleList); + +/** + This class represents single font face with set parameters (point size, + antialiasing). + */ +class wxFontInstanceBase +{ +protected: + wxFontInstanceBase(float ptSize, bool aa) : m_ptSize(ptSize), m_aa(aa) {} + virtual ~wxFontInstanceBase() {} + +public: + float GetPointSize() const { return m_ptSize; } + bool IsAntiAliased() const { return m_aa; } + +protected: + float m_ptSize; + bool m_aa; +}; + + +/// This class represents loaded font face (bundle+weight+italics). +class wxFontFaceBase +{ +protected: + /// Ctor. Creates object with reference count = 0, Acquire() must be + /// called after the object is created. + wxFontFaceBase(); + virtual ~wxFontFaceBase(); + +public: + /// Increases reference count of the face + virtual void Acquire(); + + /** + Decreases reference count of the face. Call this when you no longer + use the object returned by wxFontBundle. Note that this doesn't destroy + the object, but only optionally shuts it down, so it's possible to + call Acquire() and Release() more than once. + */ + virtual void Release(); + + /** + Returns instance of the font at given size. + + @param ptSize point size of the font to create; note that this is + a float and not integer, it should be wxFont's point + size multipled by wxDC's scale factor + @param aa should the font be antialiased? + */ + virtual wxFontInstance *GetFontInstance(float ptSize, bool aa); + +protected: + /// Called to create a new instance of the font by GetFontInstance() if + /// it wasn't found it cache. + virtual wxFontInstance *CreateFontInstance(float ptSize, bool aa) = 0; + +protected: + unsigned m_refCnt; + wxFontInstanceList *m_instances; +}; + +/** + This class represents font bundle. Font bundle is set of faces that have + the same name, but differ in weight and italics. + */ +class wxFontBundleBase +{ +public: + wxFontBundleBase(); + virtual ~wxFontBundleBase(); + + /// Returns name of the bundle + virtual wxString GetName() const = 0; + + /// Returns true if the font is fixe-width + virtual bool IsFixed() const = 0; + + /// Type of faces in the bundle + enum FaceType + { + // NB: values of these constants are set so that it's possible to + // make OR-combinations of them and still get valid enum element + FaceType_Regular = 0, + FaceType_Italic = 1, + FaceType_Bold = 2, + FaceType_BoldItalic = FaceType_Italic | FaceType_Bold, + + FaceType_Max + }; + + /// Returns true if the given face is available + bool HasFace(FaceType type) const { return m_faces[type] != NULL; } + + /** + Returns font face object that can be used to render font of given type. + + Note that this method can only be called if HasFace(type) returns true. + + Acquire() was called on the returned object, you must call Release() + when you stop using it. + */ + wxFontFace *GetFace(FaceType type) const; + + /** + Returns font face object that can be used to render given font. + + Acquire() was called on the returned object, you must call Release() + when you stop using it. + */ + wxFontFace *GetFaceForFont(const wxFontMgrFontRefData& font) const; + +protected: + wxFontFace *m_faces[FaceType_Max]; +}; + + +/** + Base class for wxFontsManager class, which manages the list of all + available fonts and their loaded instances. + */ +class wxFontsManagerBase +{ +protected: + wxFontsManagerBase(); + virtual ~wxFontsManagerBase(); + +public: + /// Returns the font manager singleton, creating it if it doesn't exist + static wxFontsManager *Get(); + + /// Called by wxApp to shut down the manager + static void CleanUp(); + + /// Returns list of all available font bundles + const wxFontBundleList& GetBundles() const { return *m_list; } + + /** + Returns object representing font bundle with the given name. + + The returned object is owned by wxFontsManager, you must not delete it. + */ + wxFontBundle *GetBundle(const wxString& name) const; + + /** + Returns object representing font bundle that can be used to render + given font. + + The returned object is owned by wxFontsManager, you must not delete it. + */ + wxFontBundle *GetBundleForFont(const wxFontMgrFontRefData& font) const; + + /// This method must be called by derived + void AddBundle(wxFontBundle *bundle); + + /// Returns default facename for given wxFont family + virtual wxString GetDefaultFacename(wxFontFamily family) const = 0; + +private: + wxFontBundleHash *m_hash; + wxFontBundleList *m_list; + +protected: + static wxFontsManager *ms_instance; +}; + + + +#if defined(__WXMGL__) + #include "wx/mgl/private/fontmgr.h" +#elif defined(__WXDFB__) + #include "wx/dfb/private/fontmgr.h" +#endif + + + +/// wxFontMgrFontRefData implementation using wxFontsManager classes +struct wxFontMgrFontRefData : public wxObjectRefData +{ +public: + wxFontMgrFontRefData(int size = wxDEFAULT, + int family = wxDEFAULT, + int style = wxDEFAULT, + int weight = wxDEFAULT, + bool underlined = false, + const wxString& faceName = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT); + wxFontMgrFontRefData(const wxFontMgrFontRefData& data); + ~wxFontMgrFontRefData(); + + wxFontBundle *GetFontBundle() const; + wxFontInstance *GetFontInstance(float scale, bool antialiased) const; + + bool IsFixedWidth() const { return GetFontBundle()->IsFixed(); } + + const wxNativeFontInfo *GetNativeFontInfo() const { return &m_info; } + + int GetPointSize() const { return m_info.pointSize; } + wxString GetFaceName() const { return m_info.faceName; } + int GetFamily() const { return m_info.family; } + int GetStyle() const { return m_info.style; } + int GetWeight() const { return m_info.weight; } + bool GetUnderlined() const { return m_info.underlined; } + wxFontEncoding GetEncoding() const { return m_info.encoding; } + + void SetPointSize(int pointSize); + void SetFamily(int family); + void SetStyle(int style); + void SetWeight(int weight); + void SetFaceName(const wxString& faceName); + void SetUnderlined(bool underlined); + void SetEncoding(wxFontEncoding encoding); + + // Unofficial API, don't use + void SetNoAntiAliasing(bool no); + bool GetNoAntiAliasing() const { return m_noAA; } + +private: + void EnsureValidFont(); + + wxNativeFontInfo m_info; + bool m_noAA; + + wxFontFace *m_fontFace; + wxFontBundle *m_fontBundle; + bool m_fontValid; +}; + +#endif // _WX_PRIVATE_FONTMGR_H_ diff --git a/src/common/fontmgrcmn.cpp b/src/common/fontmgrcmn.cpp new file mode 100644 index 0000000000..6a5d0683ec --- /dev/null +++ b/src/common/fontmgrcmn.cpp @@ -0,0 +1,345 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/common/fontmgrcmn.cpp +// Purpose: font management for ports that don't have their own +// Author: Vaclav Slavik +// Created: 2006-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) +// (c) 2006 REA Elektronik GmbH +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/private/fontmgr.h" + +#include "wx/listimpl.cpp" +#include "wx/hashmap.h" + +WX_DECLARE_LIST(wxFontInstance, wxFontInstanceList); +WX_DEFINE_LIST(wxFontInstanceList) +WX_DEFINE_LIST(wxFontBundleList) +WX_DECLARE_HASH_MAP(wxString, wxFontBundle*, + wxStringHash, wxStringEqual, + wxFontBundleHash); + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxFontFaceBase +// ---------------------------------------------------------------------------- + +wxFontFaceBase::wxFontFaceBase() + : m_refCnt(0) +{ + m_instances = new wxFontInstanceList; + m_instances->DeleteContents(true); +} + +wxFontFaceBase::~wxFontFaceBase() +{ + delete m_instances; +} + +void wxFontFaceBase::Acquire() +{ + m_refCnt++; +} + +void wxFontFaceBase::Release() +{ + if ( --m_refCnt == 0 ) + { + m_instances->Clear(); + } +} + +wxFontInstance *wxFontFaceBase::GetFontInstance(float ptSize, bool aa) +{ + wxASSERT_MSG( m_refCnt > 0, _T("font library not loaded!") ); + + wxFontInstance *i; + wxFontInstanceList::Node *node; + + for ( node = m_instances->GetFirst(); node; node = node->GetNext() ) + { + i = node->GetData(); + if ( i->GetPointSize() == ptSize && i->IsAntiAliased() == aa ) + return i; + } + + i = CreateFontInstance(ptSize, aa); + m_instances->Append(i); + return i; +} + +// ---------------------------------------------------------------------------- +// wxFontBundleBase +// ---------------------------------------------------------------------------- + +wxFontBundleBase::wxFontBundleBase() +{ + for (int i = 0; i < FaceType_Max; i++) + m_faces[i] = NULL; +} + +wxFontBundleBase::~wxFontBundleBase() +{ + for (int i = 0; i < FaceType_Max; i++) + delete m_faces[i]; +} + +wxFontFace *wxFontBundleBase::GetFace(FaceType type) const +{ + wxFontFace *f = m_faces[type]; + + wxCHECK_MSG( f, NULL, _T("no such face in font bundle") ); + + f->Acquire(); + + return f; +} + +wxFontFace * +wxFontBundleBase::GetFaceForFont(const wxFontMgrFontRefData& font) const +{ + wxASSERT_MSG( font.GetFaceName().empty() || font.GetFaceName() == GetName(), + _T("calling GetFaceForFont for incompatible font") ); + + int type = FaceType_Regular; + + if ( font.GetWeight() == wxBOLD ) + type |= FaceType_Bold; + + // FIXME -- this should read "if ( font->GetStyle() == wxITALIC )", + // but since MGL neither DFB supports slant, we try to display it with + // italic face (better than nothing...) + if ( font.GetStyle() == wxITALIC || font.GetStyle() == wxSLANT ) + { + if ( HasFace((FaceType)(type | FaceType_Italic)) ) + type |= FaceType_Italic; + } + + if ( !HasFace((FaceType)type) ) + { + for (int i = 0; i < FaceType_Max; i++) + { + if ( HasFace((FaceType)i) ) + return GetFace((FaceType)i); + } + + wxFAIL_MSG( _T("no face") ); + return NULL; + } + + return GetFace((FaceType)type); +} + +// ---------------------------------------------------------------------------- +// wxFontsManagerBase +// ---------------------------------------------------------------------------- + +wxFontsManager *wxFontsManagerBase::ms_instance = NULL; + +wxFontsManagerBase::wxFontsManagerBase() +{ + m_hash = new wxFontBundleHash(); + m_list = new wxFontBundleList; + m_list->DeleteContents(true); +} + +wxFontsManagerBase::~wxFontsManagerBase() +{ + delete m_hash; + delete m_list; +} + +/* static */ +wxFontsManager *wxFontsManagerBase::Get() +{ + if ( !ms_instance ) + ms_instance = new wxFontsManager(); + return ms_instance; +} + +/* static */ +void wxFontsManagerBase::CleanUp() +{ + wxDELETE(ms_instance); +} + +wxFontBundle *wxFontsManagerBase::GetBundle(const wxString& name) const +{ + return (*m_hash)[name.Lower()]; +} + +wxFontBundle * +wxFontsManagerBase::GetBundleForFont(const wxFontMgrFontRefData& font) const +{ + wxFontBundle *bundle = NULL; + + wxString facename = font.GetFaceName(); + if ( !facename.empty() ) + bundle = GetBundle(facename); + + if ( !bundle ) + { + facename = GetDefaultFacename((wxFontFamily)font.GetFamily()); + if ( !facename.empty() ) + bundle = GetBundle(facename); + } + + if ( !bundle ) + { + if ( m_list->GetFirst() ) + bundle = m_list->GetFirst()->GetData(); + else + wxFAIL_MSG(wxT("Fatal error, no fonts available!")); + } + + return bundle; +} + +void wxFontsManagerBase::AddBundle(wxFontBundle *bundle) +{ + (*m_hash)[bundle->GetName().Lower()] = bundle; + m_list->Append(bundle); +} + + +// ---------------------------------------------------------------------------- +// wxFontMgrFontRefData +// ---------------------------------------------------------------------------- + +wxFontMgrFontRefData::wxFontMgrFontRefData(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) +{ + if ( family == wxDEFAULT ) + family = wxSWISS; + if ( style == wxDEFAULT ) + style = wxNORMAL; + if ( weight == wxDEFAULT ) + weight = wxNORMAL; + if ( size == wxDEFAULT ) + size = 12; + + m_info.family = (wxFontFamily)family; + m_info.faceName = faceName; + m_info.style = (wxFontStyle)style; + m_info.weight = (wxFontWeight)weight; + m_info.pointSize = size; + m_info.underlined = underlined; + m_info.encoding = encoding; + + m_noAA = false; + + m_fontFace = NULL; + m_fontBundle = NULL; + m_fontValid = false; +} + +wxFontMgrFontRefData::wxFontMgrFontRefData(const wxFontMgrFontRefData& data) +{ + m_info = data.m_info; + m_noAA = data.m_noAA; + + m_fontFace = data.m_fontFace; + m_fontBundle = data.m_fontBundle; + m_fontValid = data.m_fontValid; + if ( m_fontFace ) + m_fontFace->Acquire(); +} + +wxFontMgrFontRefData::~wxFontMgrFontRefData() +{ + if ( m_fontFace ) + m_fontFace->Release(); +} + +wxFontBundle *wxFontMgrFontRefData::GetFontBundle() const +{ + wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont(); + return m_fontBundle; +} + +wxFontInstance * +wxFontMgrFontRefData::GetFontInstance(float scale, bool antialiased) const +{ + wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont(); + return m_fontFace->GetFontInstance(m_info.pointSize * scale, + antialiased && !m_noAA); +} + +void wxFontMgrFontRefData::SetPointSize(int pointSize) +{ + m_info.pointSize = pointSize; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetFamily(int family) +{ + m_info.family = (wxFontFamily)family; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetStyle(int style) +{ + m_info.style = (wxFontStyle)style; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetWeight(int weight) +{ + m_info.weight = (wxFontWeight)weight; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetFaceName(const wxString& faceName) +{ + m_info.faceName = faceName; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetUnderlined(bool underlined) +{ + m_info.underlined = underlined; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetEncoding(wxFontEncoding encoding) +{ + m_info.encoding = encoding; + m_fontValid = false; +} + +void wxFontMgrFontRefData::SetNoAntiAliasing(bool no) +{ + m_noAA = no; +} + + +void wxFontMgrFontRefData::EnsureValidFont() +{ + if ( !m_fontValid ) + { + wxFontFace *old = m_fontFace; + + m_fontBundle = wxFontsManager::Get()->GetBundleForFont(*this); + m_fontFace = m_fontBundle->GetFaceForFont(*this); + + if ( old ) + old->Release(); + } +} diff --git a/src/dfb/app.cpp b/src/dfb/app.cpp index 2883ee6f54..5f7a8004eb 100644 --- a/src/dfb/app.cpp +++ b/src/dfb/app.cpp @@ -20,6 +20,7 @@ #include "wx/evtloop.h" #include "wx/dfb/private.h" +#include "wx/private/fontmgr.h" //----------------------------------------------------------------------------- // wxApp initialization @@ -57,6 +58,8 @@ void wxApp::CleanUp() { wxAppBase::CleanUp(); + wxFontsManager::CleanUp(); + wxEventLoop::CleanUp(); wxIDirectFB::CleanUp(); } diff --git a/src/dfb/dc.cpp b/src/dfb/dc.cpp index d8d9176e83..8853fe0878 100644 --- a/src/dfb/dc.cpp +++ b/src/dfb/dc.cpp @@ -390,10 +390,21 @@ void wxDC::SetFont(const wxFont& font) wxFont f(font.Ok() ? font : DEFAULT_FONT); - if ( !m_surface->SetFont(f.GetDirectFBFont()) ) - return; + wxFont oldfont(m_font); m_font = f; + + if ( !m_surface->SetFont(GetCurrentFont()) ) + { + m_font = oldfont; + return; + } +} + +wxIDirectFBFontPtr wxDC::GetCurrentFont() const +{ + bool aa = (GetDepth() > 8); + return m_font.GetDirectFBFont(aa); } void wxDC::SetBackground(const wxBrush& brush) @@ -450,7 +461,7 @@ wxCoord wxDC::GetCharHeight() const wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); int h = -1; - m_font.GetDirectFBFont()->GetHeight(&h); + GetCurrentFont()->GetHeight(&h); return YDEV2LOGREL(h); } @@ -460,7 +471,7 @@ wxCoord wxDC::GetCharWidth() const wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); int w = -1; - m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w); + GetCurrentFont()->GetStringWidth("H", 1, &w); // VS: YDEV is corrent, it should *not* be XDEV, because font's are only // scaled according to m_scaleY return YDEV2LOGREL(w); @@ -483,7 +494,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord xx = 0, yy = 0; DFBRectangle rect; - wxIDirectFBFontPtr f = m_font.GetDirectFBFont(); + wxIDirectFBFontPtr f = GetCurrentFont(); if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) ) { diff --git a/src/dfb/fontmgr.cpp b/src/dfb/fontmgr.cpp new file mode 100644 index 0000000000..53849e210d --- /dev/null +++ b/src/dfb/fontmgr.cpp @@ -0,0 +1,217 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/dfb/fontmgr.cpp +// Purpose: font management for wxDFB +// Author: Vaclav Slavik +// Created: 2006-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) +// (c) 2006 REA Elektronik GmbH +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/fileconf.h" +#include "wx/filename.h" + +#include "wx/private/fontmgr.h" +#include "wx/dfb/wrapdfb.h" + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxFontInstance +// ---------------------------------------------------------------------------- + +wxFontInstance::wxFontInstance(float ptSize, bool aa, + const wxString& filename) + : wxFontInstanceBase(ptSize, aa) +{ + int scrSizePx, scrSizeMM; + wxDisplaySize(NULL, &scrSizePx); + wxDisplaySizeMM(NULL, &scrSizeMM); + double dpi = (scrSizePx / (scrSizeMM * mm2inches)); + // NB: DFB's fract_height value is 32bit integer with the last 6 bit + // representing fractional value, hence the multiplication by 64; + // 1pt=1/72inch, hence "/ 72" + int pixSize = int(ptSize * dpi * 64 / 72); + + DFBFontDescription desc; + desc.flags = (DFBFontDescriptionFlags)( + DFDESC_ATTRIBUTES | DFDESC_FRACT_HEIGHT); + desc.attributes = aa ? DFFA_NONE : DFFA_MONOCHROME; + desc.fract_height = pixSize; + m_font = wxIDirectFB::Get()->CreateFont(filename.fn_str(), &desc); + + wxASSERT_MSG( m_font, _T("cannot create font instance") ); +} + +// ---------------------------------------------------------------------------- +// wxFontFace +// ---------------------------------------------------------------------------- + +wxFontInstance *wxFontFace::CreateFontInstance(float ptSize, bool aa) +{ + return new wxFontInstance(ptSize, aa, m_fileName); +} + +// ---------------------------------------------------------------------------- +// wxFontBundle +// ---------------------------------------------------------------------------- + +wxFontBundle::wxFontBundle(const wxString& name, + const wxString& fileRegular, + const wxString& fileBold, + const wxString& fileItalic, + const wxString& fileBoldItalic, + bool isFixed) +{ + m_name = name; + m_isFixed = isFixed; + + if ( !fileRegular.empty() ) + m_faces[FaceType_Regular] = new wxFontFace(fileRegular); + if ( !fileItalic.empty() ) + m_faces[FaceType_Italic] = new wxFontFace(fileItalic); + if ( !fileBold.empty() ) + m_faces[FaceType_Bold] = new wxFontFace(fileBold); + if ( !fileBoldItalic.empty() ) + m_faces[FaceType_BoldItalic] = new wxFontFace(fileBoldItalic); +} + +// ---------------------------------------------------------------------------- +// wxFontsManager +// ---------------------------------------------------------------------------- + +/* + The code below parses font configuration file ${WXDFB_FONTDIR}/FontsIndex. + By default, the directory is $prefix/share/wx/fonts, but can be ovewritten + by setting WXDFB_FONTDIR environment variable. + + The file is standard wxFileConfig file text file. Each toplevel group + specifies one font bundle, font's name is the name of group. Group's entries + look like this: + + [Font Name] + # font files (at least one of them must be present): + Regular=RegularFaceFile.ttf + Italic=ItalicFaceFile.ttf + Bold=BoldFaceFile.ttf + BoldItalic=BoldItalicFaceFile.ttf + # optional tag indicating this font is fixed-with (default is false): + IsFixed=1 + + Additionally, there may be DefaultXXX entries at the toplevel for every + family XXX and a Default entry that is shortcut for setting all families' + default, their value is name of the default font: + + # optional tags indicating the default font for given family: + DefaultDecorative=Font Name + DefaultRoman=Font Name + DefaultScript=Font Name + DefaultSwiss=Font Name + DefaultModern=Font Name + DefaultTeletype=Font Name + # indicate the font that is default for all families (optional): + Default=Font Name + */ + +void wxFontsManager::AddAllFonts() +{ + wxString dir = _T(wxINSTALL_PREFIX "/share/wx/fonts"); + wxGetEnv(_T("WXDFB_FONTDIR"), &dir); + + wxString indexFile = dir + _T("/FontsIndex"); + + if ( !wxFileName::FileExists(indexFile) ) + { + wxLogWarning(_("No fonts found in %s"), dir.c_str()); + return; + } + + wxLogTrace(_T("font"), _T("adding fonts from %s"), dir.c_str()); + + wxFileConfig cfg(wxEmptyString, wxEmptyString, + indexFile, wxEmptyString, + wxCONFIG_USE_LOCAL_FILE); + + long i; + wxString name; + for ( bool cont = cfg.GetFirstGroup(name, i); + cont; + cont = cfg.GetNextGroup(name, i) ) + { + AddFont(dir, name, cfg); + } + + // set default fonts for families: + SetDefaultFonts(cfg); +} + +static wxString +ReadFilePath(const wxString& name, const wxString& dir, wxFileConfig& cfg) +{ + wxString p = cfg.Read(name, wxEmptyString); + + if ( p.empty() || wxFileName(p).IsAbsolute() ) + return p; + + return dir + _T("/") + p; +} + +void wxFontsManager::AddFont(const wxString& dir, + const wxString& name, + wxFileConfig& cfg) +{ + wxLogTrace(_T("font"), _T("adding font '%s'"), name.c_str()); + + wxConfigPathChanger ch(&cfg, wxString::Format(_T("/%s/"), name.c_str())); + + AddBundle + ( + new wxFontBundle + ( + name, + ReadFilePath(_T("Regular"), dir, cfg), + ReadFilePath(_T("Italic"), dir, cfg), + ReadFilePath(_T("Bold"), dir, cfg), + ReadFilePath(_T("BoldItalic"), dir, cfg), + cfg.Read(_T("IsFixed"), (long)false) + ) + ); +} + +void wxFontsManager::SetDefaultFonts(wxFileConfig& cfg) +{ + wxString name; + + if ( cfg.Read(_T("Default"), &name) ) + { + m_defaultFacenames[wxFONTFAMILY_DECORATIVE] = + m_defaultFacenames[wxFONTFAMILY_ROMAN] = + m_defaultFacenames[wxFONTFAMILY_SCRIPT] = + m_defaultFacenames[wxFONTFAMILY_SWISS] = + m_defaultFacenames[wxFONTFAMILY_MODERN] = + m_defaultFacenames[wxFONTFAMILY_TELETYPE] = name; + } + + if ( cfg.Read(_T("DefaultDecorative"), &name) ) + m_defaultFacenames[wxFONTFAMILY_DECORATIVE] = name; + if ( cfg.Read(_T("DefaultRoman"), &name) ) + m_defaultFacenames[wxFONTFAMILY_ROMAN] = name; + if ( cfg.Read(_T("DefaultScript"), &name) ) + m_defaultFacenames[wxFONTFAMILY_SCRIPT] = name; + if ( cfg.Read(_T("DefaultSwiss"), &name) ) + m_defaultFacenames[wxFONTFAMILY_SWISS] = name; + if ( cfg.Read(_T("DefaultModern"), &name) ) + m_defaultFacenames[wxFONTFAMILY_MODERN] = name; + if ( cfg.Read(_T("DefaultTeletype"), &name) ) + m_defaultFacenames[wxFONTFAMILY_TELETYPE] = name; +} diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index 53c61fad16..1a614e3f81 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -32,6 +32,7 @@ #include "wx/univ/colschem.h" #include "wx/sysopt.h" #include "wx/mgl/private.h" +#include "wx/private/fontmgr.h" //----------------------------------------------------------------------------- // wxApp::Exit() @@ -283,14 +284,8 @@ bool wxApp::Initialize(int& argc, wxChar **argv) return false; } - // must do it before calling wxAppBase::Initialize(), because fonts are - // needed by stock lists which are created there - wxTheFontsManager = new wxFontsManager; - if ( !wxAppBase::Initialize(argc, argv) ) { - delete wxTheFontsManager; - wxTheFontsManager = NULL; MGL_exit(); return false; } @@ -313,8 +308,7 @@ struct wxMGLFinalCleanup: public wxModule void OnExit() { - delete wxTheFontsManager; - wxTheFontsManager = (wxFontsManager*) NULL; + wxFontsManager::CleanUp(); wxDestroyMGL_WM(); MGL_exit(); diff --git a/src/mgl/fontenum.cpp b/src/mgl/fontenum.cpp index c3a523e17b..5659d4b643 100644 --- a/src/mgl/fontenum.cpp +++ b/src/mgl/fontenum.cpp @@ -32,6 +32,7 @@ #include "wx/encinfo.h" #include "wx/fontutil.h" +#include "wx/private/fontmgr.h" #include @@ -48,19 +49,19 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, bool fixedWidthOnly) { bool found = false; - wxMGLFontFamilyList *list = wxTheFontsManager->GetFamilyList(); - wxMGLFontFamilyList::Node *node; - wxMGLFontFamily *f = NULL; + const wxFontBundleList& list = wxFontsManager::Get()->GetBundles(); + wxFontBundleList::Node *node; + wxFontBundle *f = NULL; wxNativeEncodingInfo info; if ( encoding != wxFONTENCODING_SYSTEM ) wxGetNativeFontEncoding(encoding, &info); - for (node = list->GetFirst(); node; node = node->GetNext()) + for (node = list.GetFirst(); node; node = node->GetNext()) { f = node->GetData(); info.facename = f->GetName(); - if ( (!fixedWidthOnly || f->GetInfo()->isFixed) && + if ( (!fixedWidthOnly || f->IsFixed()) && (encoding == wxFONTENCODING_SYSTEM || wxTestFontEncoding(info)) ) { found = true; diff --git a/src/mgl/fontmgr.cpp b/src/mgl/fontmgr.cpp new file mode 100644 index 0000000000..4bcae31029 --- /dev/null +++ b/src/mgl/fontmgr.cpp @@ -0,0 +1,169 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/mgl/fontmgr.cpp +// Purpose: font management for wxMGL +// Author: Vaclav Slavik +// Created: 2006-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) +// (c) 2006 REA Elektronik GmbH +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/private/fontmgr.h" +#include "wx/sysopt.h" + +#include + +static int gs_antialiasingThreshold = -1; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxFontInstance +// ---------------------------------------------------------------------------- + +wxFontInstance::wxFontInstance(float ptSize, bool aa, font_lib_t *fontLib) + : wxFontInstanceBase(ptSize, aa) +{ + m_font = MGL_loadFontInstance(fontLib, ptSize, 0.0, 0.0, aa); + + wxASSERT_MSG( m_font, _T("cannot create font instance") ); +} + +wxFontInstance::~wxFontInstance() +{ + if ( m_font ) + MGL_unloadFontInstance(m_font); +} + +// ---------------------------------------------------------------------------- +// wxFontFace +// ---------------------------------------------------------------------------- + +void wxFontFace::Acquire() +{ + wxFontFaceBase::Acquire(); + + if ( m_refCnt == 1 ) + { + wxCHECK_RET( m_fontLib == NULL, _T("font lib already created") ); + + wxLogTrace("mgl_font", "opening library '%s'", m_fileName.mb_str()); + m_fontLib = MGL_openFontLib(m_fileName.fn_str()); + } +} + +void wxFontFace::Release() +{ + wxFontFaceBase::Release(); + + if ( m_refCnt == 0 ) + { + wxCHECK_RET( m_fontLib != NULL, _T("font lib not created") ); + + wxLogTrace("mgl_font", "closing library '%s'", m_fileName.mb_str()); + MGL_closeFontLib(m_fontLib); + m_fontLib = NULL; + } +} + +wxFontInstance *wxFontFace::GetFontInstance(float ptSize, bool aa) +{ + if ( gs_antialiasingThreshold == -1 ) + { + gs_antialiasingThreshold = 10; +#if wxUSE_SYSTEM_OPTIONS + if ( wxSystemOptions::HasOption(wxT("mgl.aa-threshold")) ) + gs_antialiasingThreshold = + wxSystemOptions::GetOptionInt(wxT("mgl.aa-threshold")); + wxLogTrace("mgl_font", "AA threshold set to %i", gs_antialiasingThreshold); +#endif + } + + // Small characters don't look good when antialiased with the algorithm + // that FreeType uses (mere 2x2 supersampling), so lets disable AA + // completely for small fonts. Bitmap fonts are not antialiased either. + if ( ptSize <= gs_antialiasingThreshold || + m_fontLib->fontLibType == MGL_BITMAPFONT_LIB ) + { + aa = false; + } + + return wxFontFaceBase::GetFontInstance(ptSize, aa); +} + +wxFontInstance *wxFontFace::CreateFontInstance(float ptSize, bool aa) +{ + wxASSERT_MSG( m_fontLib, _T("font library not loaded!") ); + + return new wxFontInstance(ptSize, aa, m_fontLib); +} + +// ---------------------------------------------------------------------------- +// wxFontBundle +// ---------------------------------------------------------------------------- + +wxFontBundle::wxFontBundle(const font_info_t *info) + : m_fontInfo(info) +{ + if ( info->regularFace[0] != '\0' ) + m_faces[FaceType_Regular] = new wxFontFace(info->regularFace); + + if ( info->italicFace[0] != '\0' ) + m_faces[FaceType_Italic] = new wxFontFace(info->italicFace); + + if ( info->boldFace[0] != '\0' ) + m_faces[FaceType_Bold] = new wxFontFace(info->boldFace); + + if ( info->boldItalicFace[0] != '\0' ) + m_faces[FaceType_BoldItalic] = new wxFontFace(info->boldItalicFace); + + wxLogTrace("mgl_font", "new family '%s' (r=%s, i=%s, b=%s, bi=%s)\n", + info->familyName, info->regularFace, info->italicFace, + info->boldFace, info->boldItalicFace); +} + +// ---------------------------------------------------------------------------- +// wxFontsManager +// ---------------------------------------------------------------------------- + +wxString wxFontsManager::GetDefaultFacename(wxFontFamily family) const +{ + switch ( family ) + { + case wxSCRIPT: + return _T("Script"); + case wxDECORATIVE: + return _T("Charter"); + case wxROMAN: + return _T("Times"); + case wxTELETYPE: + case wxMODERN: + return _T("Courier"); + case wxSWISS: + case wxDEFAULT: + default: + return wxT("Helvetica"); + } +} + +static ibool MGLAPI enum_callback(const font_info_t *info, void *cookie) +{ + wxFontsManager *db = (wxFontsManager*)cookie; + db->AddBundle(new wxFontBundle(info)); + return TRUE; +} + +void wxFontsManager::AddAllFonts() +{ + MGL_enumerateFonts(enum_callback, (void*)this); +} diff --git a/src/mgl/fontutil.cpp b/src/mgl/fontutil.cpp index 5e202b2c75..16a7f0dabc 100644 --- a/src/mgl/fontutil.cpp +++ b/src/mgl/fontutil.cpp @@ -28,6 +28,7 @@ #include "wx/listimpl.cpp" #include "wx/sysopt.h" #include "wx/mgl/private.h" +#include "wx/private/fontmgr.h" #include @@ -138,311 +139,16 @@ bool wxTestFontEncoding(const wxNativeEncodingInfo& info) if ( !info.facename ) return true; - wxMGLFontFamily *family = wxTheFontsManager->GetFamily(info.facename); - if ( !family ) + wxFontBundle *bundle = wxFontsManager::Get()->GetBundle(info.facename); + if ( !bundle ) return false; - if ( family->GetInfo()->fontLibType == MGL_BITMAPFONT_LIB ) + if ( bundle->GetInfo()->fontLibType == MGL_BITMAPFONT_LIB ) + { return (info.mglEncoding == MGL_ENCODING_ASCII || info.mglEncoding == MGL_ENCODING_ISO8859_1 || info.mglEncoding == MGL_ENCODING_ISO8859_15 || info.mglEncoding == MGL_ENCODING_CP1252); - else - return true; -} - - -// ---------------------------------------------------------------------------- -// wxFontFamily, wxMGLFontInstance, wxMGLFontLibrary -// ---------------------------------------------------------------------------- - -WX_DECLARE_LIST(wxMGLFontInstance, wxMGLFontInstanceList); -WX_DEFINE_LIST(wxMGLFontInstanceList) -WX_DEFINE_LIST(wxMGLFontFamilyList) - -wxMGLFontInstance::wxMGLFontInstance(wxMGLFontLibrary *fontLib, - float pt, bool slant, bool aa) -{ - m_fontLib = fontLib; - m_font = NULL; - m_pt = pt; - m_slant = slant; - m_aa = aa; - - float slantAngle = m_slant ? 15.0 : 0.0; - - wxLogTrace("mgl_font", "loading instance of '%s' slant=%i pt=%0.1f aa=%i", - m_fontLib->GetMGLfont_lib_t()->name, m_slant, m_pt, m_aa); - m_font = MGL_loadFontInstance(m_fontLib->GetMGLfont_lib_t(), - m_pt, slantAngle, 0.0, aa); - wxASSERT_MSG( m_font, wxT("Cannot create font instance.") ); -} - -wxMGLFontInstance::~wxMGLFontInstance() -{ - wxLogTrace("mgl_font", "unloading instance of '%s' slant=%i pt=%0.1f aa=%i", - m_fontLib->GetMGLfont_lib_t()->name, m_slant, m_pt, m_aa); - if ( m_font ) - MGL_unloadFontInstance(m_font); -} - -wxMGLFontLibrary::wxMGLFontLibrary(const wxString& filename, int type, - wxMGLFontFamily *parentFamily) -{ - m_family = parentFamily; - m_type = type; - m_fileName = filename; - m_refs = 0; - m_fontLib = NULL; - - m_instances = new wxMGLFontInstanceList; - m_instances->DeleteContents(true); -} - -wxMGLFontLibrary::~wxMGLFontLibrary() -{ - wxLogTrace("mgl_font", "font library dtor '%s'", m_fileName.mb_str()); - delete m_instances; -} - -void wxMGLFontLibrary::IncRef() -{ - wxLogTrace("mgl_font", "incRef(%u) '%s'", m_refs, m_fileName.c_str()); - if ( m_refs++ == 0 ) - { - wxLogTrace("mgl_font", "opening library '%s'", m_fileName.mb_str()); - m_fontLib = MGL_openFontLib(m_fileName.mb_str()); } -} - -void wxMGLFontLibrary::DecRef() -{ - wxLogTrace("mgl_font", "decRef(%u) '%s'", m_refs, m_fileName.c_str()); - if ( --m_refs == 0 ) - { - wxLogTrace("mgl_font", "killing instances of '%s'", m_fileName.mb_str()); - m_instances->Clear(); - wxLogTrace("mgl_font", "closing library '%s'", m_fileName.mb_str()); - MGL_closeFontLib(m_fontLib); - m_fontLib = NULL; - } -} - -static int gs_antialiasingThreshold = -1; - -wxMGLFontInstance *wxMGLFontLibrary::GetFontInstance(wxFont *font, - float scale, bool aa) -{ - wxASSERT_MSG(m_refs > 0 && m_fontLib, wxT("font library not loaded!")); - - wxString facename; - float pt = (float)font->GetPointSize() * scale; - - if ( gs_antialiasingThreshold == -1 ) - { - gs_antialiasingThreshold = 10; -#if wxUSE_SYSTEM_OPTIONS - if ( wxSystemOptions::HasOption(wxT("mgl.aa-threshold")) ) - gs_antialiasingThreshold = - wxSystemOptions::GetOptionInt(wxT("mgl.aa-threshold")); - wxLogTrace("mgl_font", "AA threshold set to %i", gs_antialiasingThreshold); -#endif - } - - // Small characters don't look good when antialiased with the algorithm - // that FreeType uses (mere 2x2 supersampling), so lets disable it AA - // completely for small fonts. - bool antialiased = false; - if (( pt > gs_antialiasingThreshold ) && - ( m_fontLib->fontLibType != MGL_BITMAPFONT_LIB ) ) - antialiased = aa; - - bool slant = (((m_type & wxFONTFACE_ITALIC) == 0) && - (font->GetStyle() == wxSLANT || font->GetStyle() == wxITALIC)); - - // FIXME_MGL -- MGL does not yet support slant, although the API is there - slant = false; - - wxLogTrace("mgl_font", "requested instance of '%s' slant=%i pt=%0.1f aa=%i", - m_fileName.mb_str(), slant, pt, antialiased); - - wxMGLFontInstance *i; - wxMGLFontInstanceList::Node *node; - - for (node = m_instances->GetFirst(); node; node = node->GetNext()) - { - i = node->GetData(); - if ( i->GetPt() == pt && i->GetSlant() == slant && - i->GetAA() == antialiased ) - { - wxLogTrace("mgl_font", " got from cache: slant=%i pt=%0.1f aa=%i", - i->GetSlant(), i->GetPt(), i->GetAA()); - return i; - } - } - - i = new wxMGLFontInstance(this, pt, slant, antialiased); - m_instances->Append(i); - return i; -} - - -wxMGLFontFamily::wxMGLFontFamily(const font_info_t *info) -{ - m_name = info->familyName; - m_fontInfo = info; - - if ( info->regularFace[0] == '\0' ) - m_fontLibs[wxFONTFACE_REGULAR] = NULL; - else - m_fontLibs[wxFONTFACE_REGULAR] = - new wxMGLFontLibrary(info->regularFace, wxFONTFACE_REGULAR, this); - - if ( info->italicFace[0] == '\0' ) - m_fontLibs[wxFONTFACE_ITALIC] = NULL; - else - m_fontLibs[wxFONTFACE_ITALIC] = - new wxMGLFontLibrary(info->italicFace, wxFONTFACE_ITALIC, this); - - if ( info->boldFace[0] == '\0' ) - m_fontLibs[wxFONTFACE_BOLD] = NULL; - else - m_fontLibs[wxFONTFACE_BOLD] = - new wxMGLFontLibrary(info->boldFace, wxFONTFACE_BOLD, this); - - if ( info->boldItalicFace[0] == '\0' ) - m_fontLibs[wxFONTFACE_BOLD_ITALIC] = NULL; else - m_fontLibs[wxFONTFACE_BOLD_ITALIC] = - new wxMGLFontLibrary(info->boldItalicFace, wxFONTFACE_BOLD_ITALIC, this); - - wxLogTrace("mgl_font", "new family '%s' (r=%s, i=%s, b=%s, bi=%s)\n", - info->familyName, info->regularFace, info->italicFace, - info->boldFace, info->boldItalicFace); -} - -wxMGLFontFamily::~wxMGLFontFamily() -{ - for (size_t i = 0; i < wxFONTFACE_MAX; i++) - delete m_fontLibs[i]; -} - -bool wxMGLFontFamily::HasFace(int type) const -{ - return (m_fontLibs[type] != NULL); -} - - -// ---------------------------------------------------------------------------- -// wxFontsManager -// ---------------------------------------------------------------------------- - -wxMGLFontLibrary *wxFontsManager::GetFontLibrary(wxFont *font) -{ - wxMGLFontFamily *family; - int type; - wxString facename = font->GetFaceName(); - - if ( !facename.empty() ) - family = GetFamily(facename); - else - family = NULL; - - if ( !family ) - { - facename.Empty(); - switch (font->GetFamily()) - { - case wxSCRIPT: - facename = wxT("Script"); - break; - case wxDECORATIVE: - facename = wxT("Charter"); - break; - case wxROMAN: - facename = wxT("Times"); - break; - case wxTELETYPE: - case wxMODERN: - facename = wxT("Courier"); - break; - case wxSWISS: - facename = wxT("Helvetica"); - break; - case wxDEFAULT: - default: - facename = wxT("Helvetica"); - break; - } - - family = GetFamily(facename); - if ( !family ) - { - if ( m_list->GetFirst() ) - family = m_list->GetFirst()->GetData(); - else - wxFAIL_MSG(wxT("Fatal error, no fonts available!")); - } - } - - type = wxFONTFACE_REGULAR; - - if ( font->GetWeight() == wxBOLD ) - type |= wxFONTFACE_BOLD; - - // FIXME_MGL -- this should read "if ( font->GetStyle() == wxITALIC )", - // but since MGL does not yet support slant, we try to display it with - // italic face (better than nothing...) - if ( font->GetStyle() == wxITALIC || font->GetStyle() == wxSLANT ) - { - if ( family->HasFace(type | wxFONTFACE_ITALIC) ) - type |= wxFONTFACE_ITALIC; - } - if ( !family->HasFace(type) ) - { - for (int i = 0; i < wxFONTFACE_MAX; i++) - if ( family->HasFace(i) ) - { - type = i; - break; - } - } - - return family->GetLibrary(type); -} - -static ibool MGLAPI enum_callback(const font_info_t *info, void *cookie) -{ - wxFontsManager *db = (wxFontsManager*)cookie; - db->AddFamily(info); - return TRUE; -} - -wxFontsManager::wxFontsManager() -{ - m_hash = new wxHashTable(wxKEY_STRING); - m_hash->DeleteContents(false); - m_list = new wxMGLFontFamilyList; - m_list->DeleteContents(true); - MGL_enumerateFonts(enum_callback, (void*)this); -} - -wxFontsManager::~wxFontsManager() -{ - delete m_hash; - delete m_list; -} - -void wxFontsManager::AddFamily(const font_info_t *info) -{ - wxMGLFontFamily *f = new wxMGLFontFamily(info); - m_hash->Put(f->GetName().Lower(), f); - m_list->Append(f); -} - -wxMGLFontFamily *wxFontsManager::GetFamily(const wxString& name) const -{ - return (wxMGLFontFamily*)m_hash->Get(name.Lower()); + return true; } - - -wxFontsManager *wxTheFontsManager = NULL; -- 2.45.2