1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 5 сент. 2017 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef UI_TK_UTIL_LSPFONT_H_ 23 #define UI_TK_UTIL_LSPFONT_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPWidget; 30 31 class LSPFont 32 { 33 protected: 34 LSPDisplay *pDisplay; 35 LSPWidget *pWidget; 36 37 Font sFont; 38 LSPColor sColor; 39 40 mutable font_parameters_t sFP; 41 42 private: 43 inline bool sync_font_parameters() const; 44 inline bool sync_font_parameters(ISurface *s) const; 45 inline void construct(LSPDisplay *dpy, LSPWidget *widget); 46 47 protected: 48 virtual void on_change(); 49 50 void trigger_change(); 51 52 public: 53 explicit LSPFont(LSPDisplay *dpy); 54 explicit LSPFont(LSPWidget *widget); 55 explicit LSPFont(LSPDisplay *dpy, LSPWidget *widget); 56 explicit LSPFont(LSPWidget *widget, LSPDisplay *dpy); 57 virtual ~LSPFont(); 58 59 void init(); 60 void init(const LSPFont *f); 61 62 public: bold()63 inline bool bold() const { return sFont.is_bold(); } italic()64 inline bool italic() const { return sFont.is_italic(); } underline()65 inline bool underline() const { return sFont.is_underline(); } size()66 inline float size() const { return sFont.get_size(); } name()67 inline const char *name() const { return sFont.get_name(); } 68 float ascent() const; 69 float descent() const; 70 float height() const; 71 float max_x_advance() const; 72 float max_y_advance() const; color()73 inline LSPColor *color() { return &sColor; } raw_color()74 inline const Color *raw_color() const { return sColor.color(); } 75 76 public: 77 void set_bold(bool b = true); 78 void set_italic(bool i = true); 79 void set_underline(bool u = true); 80 void set_size(float s); 81 void set_name(const char *name); 82 83 public: 84 bool get_parameters(font_parameters_t *fp); 85 bool get_parameters(ISurface *s, font_parameters_t *fp); 86 87 bool get_text_parameters(ISurface *s, text_parameters_t *tp, const char *text); 88 bool get_text_parameters(ISurface *s, text_parameters_t *tp, const LSPString *text); 89 bool get_text_parameters(ISurface *s, text_parameters_t *tp, const LSPString *text, ssize_t first); 90 bool get_text_parameters(ISurface *s, text_parameters_t *tp, const LSPString *text, ssize_t first, ssize_t last); 91 92 bool get_multiline_text_parameters(ISurface *s, text_parameters_t *tp, const char *text); 93 bool get_multiline_text_parameters(ISurface *s, text_parameters_t *tp, const LSPString *text); 94 bool get_multiline_text_parameters(ISurface *s, text_parameters_t *tp, const LSPString *text, ssize_t first); 95 bool get_multiline_text_parameters(ISurface *s, text_parameters_t *tp, const LSPString *text, ssize_t first, ssize_t last); 96 97 bool estimate_text_parameters(text_parameters_t *tp, const char *text); 98 bool estimate_text_parameters(text_parameters_t *tp, const LSPString *text); 99 bool estimate_text_parameters(text_parameters_t *tp, const LSPString *text, ssize_t first); 100 bool estimate_text_parameters(text_parameters_t *tp, const LSPString *text, ssize_t first, ssize_t last); 101 102 void draw(ISurface *s, float x, float y, const char *text); 103 void draw(ISurface *s, float x, float y, const LSPString *text); 104 void draw(ISurface *s, float x, float y, const LSPString *text, size_t first); 105 void draw(ISurface *s, float x, float y, const LSPString *text, size_t first, size_t last); 106 107 void draw(ISurface *s, float x, float y, const Color &c, const char *text); 108 void draw(ISurface *s, float x, float y, const Color &c, const LSPString *text); 109 void draw(ISurface *s, float x, float y, const Color &c, const LSPString *text, size_t first); 110 void draw(ISurface *s, float x, float y, const Color &c, const LSPString *text, size_t first, size_t last); 111 }; 112 113 } /* namespace tk */ 114 } /* namespace lsp */ 115 116 #endif /* UI_TK_UTIL_LSPFONT_H_ */ 117