diff options
| -rwxr-xr-x | gtk/ScintillaGTK.cxx | 33 | ||||
| -rwxr-xr-x | gtk/ScintillaGTK.h | 11 | 
2 files changed, 44 insertions, 0 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 09a389677..f0e2767f5 100755 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -144,6 +144,24 @@ static GtkWidget *PWidget(const Window &w) noexcept {  	return static_cast<GtkWidget *>(w.GetID());  } +FontOptions::FontOptions(GtkWidget *widget) noexcept { +	PangoContext *pcontext = gtk_widget_create_pango_context(widget); +	PLATFORM_ASSERT(pcontext); +	const cairo_font_options_t *options = pango_cairo_context_get_font_options(pcontext); +	// options is owned by the PangoContext so must not be freed. +	PLATFORM_ASSERT(options); +	antialias = cairo_font_options_get_antialias(options); +	order = cairo_font_options_get_subpixel_order(options); +	hint = cairo_font_options_get_hint_style(options); +	g_object_unref(pcontext); +} + +bool FontOptions::operator==(const FontOptions &other) const noexcept { +	return antialias == other.antialias && +		order == other.order && +		hint == other.hint; +} +  ScintillaGTK *ScintillaGTK::FromWidget(GtkWidget *widget) noexcept {  	ScintillaObject *scio = SCINTILLA(widget);  	return static_cast<ScintillaGTK *>(scio->pscin); @@ -661,6 +679,8 @@ void ScintillaGTK::Init() {  	vs.indicators[SC_INDICATOR_INPUT] = Indicator(INDIC_DOTS, ColourDesired(0, 0, 0xff));  	vs.indicators[SC_INDICATOR_CONVERTED] = Indicator(INDIC_COMPOSITIONTHICK, ColourDesired(0, 0, 0xff));  	vs.indicators[SC_INDICATOR_TARGET] = Indicator(INDIC_STRAIGHTBOX, ColourDesired(0, 0, 0xff)); + +	fontOptionsPrevious = FontOptions(PWidget(wText));  }  void ScintillaGTK::Finalise() { @@ -2573,10 +2593,21 @@ void ScintillaGTK::Destroy(GObject *object) {  	}  } +void ScintillaGTK::CheckForFontOptionChange() { +	FontOptions fontOptionsNow(PWidget(wText)); +	if (!(fontOptionsNow == fontOptionsPrevious)) { +		// Clear position caches +		InvalidateStyleData(); +	} +	fontOptionsPrevious = fontOptionsNow; +} +  #if GTK_CHECK_VERSION(3,0,0)  gboolean ScintillaGTK::DrawTextThis(cairo_t *cr) {  	try { +		CheckForFontOptionChange(); +  		paintState = PaintState::painting;  		repaintFullWindow = false; @@ -2675,6 +2706,8 @@ gboolean ScintillaGTK::DrawMain(GtkWidget *widget, cairo_t *cr) {  gboolean ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {  	try { +		CheckForFontOptionChange(); +  		paintState = PaintState::painting;  		rcPaint = PRectangle::FromInts( diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h index c4437e229..51d51d2ab 100755 --- a/gtk/ScintillaGTK.h +++ b/gtk/ScintillaGTK.h @@ -12,6 +12,15 @@ class ScintillaGTKAccessible;  #define OBJECT_CLASS GObjectClass +struct FontOptions { +	cairo_antialias_t antialias {}; +	cairo_subpixel_order_t order {}; +	cairo_hint_style_t hint {}; +	FontOptions() noexcept = default; +	explicit FontOptions(GtkWidget *widget) noexcept; +	bool operator==(const FontOptions &other) const noexcept; +}; +  class ScintillaGTK : public ScintillaBase {  	friend class ScintillaGTKAccessible; @@ -69,6 +78,7 @@ class ScintillaGTK : public ScintillaBase {  	bool repaintFullWindow;  	guint styleIdleID; +	FontOptions fontOptionsPrevious;  	int accessibilityEnabled;  	AtkObject *accessible; @@ -174,6 +184,7 @@ private:  	static void GetPreferredHeight(GtkWidget *widget, gint *minimalHeight, gint *naturalHeight);  #endif  	static void SizeAllocate(GtkWidget *widget, GtkAllocation *allocation); +	void CheckForFontOptionChange();  #if GTK_CHECK_VERSION(3,0,0)  	gboolean DrawTextThis(cairo_t *cr);  	static gboolean DrawText(GtkWidget *widget, cairo_t *cr, ScintillaGTK *sciThis);  | 
