1 // -*- C++ -*- 2 /** 3 * \file MetricsInfo.h 4 * This file is part of LyX, the document processor. 5 * Licence details can be found in the file COPYING. 6 * 7 * \author André Pönitz 8 * \author Stefan Schimanski 9 * 10 * Full author contact details are available in file CREDITS. 11 */ 12 13 #ifndef METRICSINFO_H 14 #define METRICSINFO_H 15 16 #include "Changes.h" 17 #include "ColorCode.h" 18 #include "FontInfo.h" 19 20 #include "support/strfwd.h" 21 #include "support/Changer.h" 22 23 #include "insets/Inset.h" 24 25 26 #include <string> 27 28 29 namespace lyx { 30 31 namespace frontend { class Painter; } 32 class BufferView; 33 class MacroContext; 34 35 36 // 37 // This is the part common to MetricsInfo and PainterInfo 38 // 39 class MetricsBase { 40 public: 41 /// 42 MetricsBase(BufferView * bv = 0, FontInfo font = FontInfo(), 43 int textwidth = 0); 44 45 /// the current view 46 BufferView * bv; 47 /// current font 48 FontInfo font; 49 /// name of current font - mathed specific 50 std::string fontname; 51 /// This is the width available in pixels 52 int textwidth; 53 /// count wether the current mathdata is nested in macro(s) 54 int macro_nesting; 55 56 /// Temporarily change a full font. 57 Changer changeFontSet(std::string const & font); 58 /// Temporarily change the font to math if needed. 59 Changer changeEnsureMath(Inset::mode_type mode = Inset::MATH_MODE); 60 // Temporarily change to the style suitable for use in fractions 61 Changer changeFrac(); 62 // Temporarily change to the style suitable for use in arrays 63 Changer changeArray(); 64 // Temporarily change the style to (script)script style 65 Changer changeScript(); 66 /// solidLineThickness()67 int solidLineThickness() const { return solid_line_thickness_; } 68 /// solidLineOffset()69 int solidLineOffset() const { return solid_line_offset_; } 70 /// dottedLineThickness()71 int dottedLineThickness() const { return dotted_line_thickness_; } 72 private: 73 int solid_line_thickness_; 74 int solid_line_offset_; 75 int dotted_line_thickness_; 76 }; 77 78 79 // 80 // This contains a MetricsBase and information that's only relevant during 81 // the first phase of the two-phase draw 82 // 83 class MetricsInfo { 84 public: 85 /// 86 MetricsInfo(); 87 /// 88 MetricsInfo(BufferView * bv, FontInfo font, int textwidth, 89 MacroContext const & mc); 90 91 /// 92 MetricsBase base; 93 /// The context to resolve macros 94 MacroContext const & macrocontext; 95 }; 96 97 98 // 99 // This contains a MetricsBase and information that's only relevant during 100 // the second phase of the two-phase draw 101 // 102 class PainterInfo { 103 public: 104 /// 105 PainterInfo(BufferView * bv, frontend::Painter & pain); 106 /// 107 void draw(int x, int y, char_type c); 108 /// 109 void draw(int x, int y, docstring const & str); 110 /// Determines the background color for the specified inset based on the 111 /// selection state, the background color inherited from the parent inset 112 /// and the inset's own background color. 113 /// \param sel whether to take the selection state into account 114 ColorCode backgroundColor(Inset const * inset, bool sel = true) const; 115 116 /// Determines the text color based on the intended color, the 117 /// change tracking state and the selection state. 118 /// \param color what the color should be by default 119 Color textColor(Color const & color) const; 120 121 /// 122 MetricsBase base; 123 /// 124 frontend::Painter & pain; 125 /// Whether the text at this point is right-to-left (for insets) 126 bool ltr_pos; 127 /// The change the parent is part of (change tracking) 128 Change change_; 129 /// Whether the parent is selected as a whole 130 bool selected; 131 /// Whether the spell checker is enabled for the parent 132 bool do_spellcheck; 133 /// True when it can be assumed that the screen has been cleared 134 bool full_repaint; 135 /// Current background color 136 ColorCode background_color; 137 }; 138 139 class TextMetricsInfo {}; 140 141 } // namespace lyx 142 143 #endif 144