|
@@ -10,11 +10,31 @@ namespace GtkCommonMark {
|
|
|
return 18;
|
|
|
}}
|
|
|
|
|
|
+ private float _scale = 1.0f;
|
|
|
+ public float font_scale {
|
|
|
+ get {
|
|
|
+ return _scale;
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _scale = value;
|
|
|
+ update_tags();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Gee.HashMap<int, Gtk.TextTag> list_tags = new Gee.HashMap<int, Gtk.TextTag>();
|
|
|
private Gee.HashMap<int, Gtk.TextTag> list_item_tags = new Gee.HashMap<int, Gtk.TextTag>();
|
|
|
private Gee.HashMap<int, Gtk.TextTag> blockquote_tags = new Gee.HashMap<int, Gtk.TextTag>();
|
|
|
private Gee.HashMap<string, Gtk.TextTag> link_tags = new Gee.HashMap<string, Gtk.TextTag>();
|
|
|
|
|
|
+ private signal void reconfigure();
|
|
|
+
|
|
|
+ private Gdk.RGBA link_colour = Gdk.RGBA() {
|
|
|
+ red = 0.0f,
|
|
|
+ green = 0.0f,
|
|
|
+ blue = 1.0f,
|
|
|
+ alpha = 1.0f
|
|
|
+ };
|
|
|
+
|
|
|
internal void associate(Gtk.TextBuffer buffer){
|
|
|
this.buffer = buffer;
|
|
|
build_tags();
|
|
@@ -98,6 +118,10 @@ namespace GtkCommonMark {
|
|
|
blue = 0,
|
|
|
alpha = 1,
|
|
|
};
|
|
|
+
|
|
|
+ paragraph.size_points = 12*font_scale;
|
|
|
+
|
|
|
+ reconfigure();
|
|
|
}
|
|
|
|
|
|
public Gtk.TextTag none {get; private set;}
|
|
@@ -147,6 +171,7 @@ namespace GtkCommonMark {
|
|
|
public virtual Gtk.TextTag get_list(int level) {
|
|
|
if(!list_tags.has_key(level)) {
|
|
|
create_list_tag_pair(level);
|
|
|
+
|
|
|
}
|
|
|
return list_tags.get(level);
|
|
|
}
|
|
@@ -167,26 +192,31 @@ namespace GtkCommonMark {
|
|
|
}
|
|
|
|
|
|
protected virtual void configure_heading (Gtk.TextTag tag, int level) {
|
|
|
- tag.size_points = 26 - (level * 2);
|
|
|
+ tag.size_points = (26 - (level * 2))*font_scale;
|
|
|
tag.pixels_below_lines = 18;
|
|
|
tag.pixels_above_lines = 18;
|
|
|
tag.weight = 700;
|
|
|
}
|
|
|
|
|
|
- protected virtual void configure_list (int level, Gtk.TextTag list_tag, Gtk.TextTag item_tag) {
|
|
|
- const int list_indent = 24;
|
|
|
+ protected virtual void configure_list (int level, Gtk.TextTag list_tag, Gtk.TextTag item_tag, bool reconfiguring = false) {
|
|
|
+ float list_indent = 36*font_scale;
|
|
|
var bullet_margin = page_margin + ((level+1) * list_indent);
|
|
|
var item_margin = bullet_margin + list_indent;
|
|
|
|
|
|
- list_tag.indent = -list_indent;
|
|
|
- list_tag.left_margin = bullet_margin;
|
|
|
+ list_tag.indent = (int)(-list_indent);
|
|
|
+ list_tag.left_margin = (int)bullet_margin;
|
|
|
var tabs = new Pango.TabArray(2, true);
|
|
|
tabs.set_tab(0, Pango.TabAlign.LEFT, 0);
|
|
|
- tabs.set_tab(1, Pango.TabAlign.LEFT, list_indent);
|
|
|
+ tabs.set_tab(1, Pango.TabAlign.LEFT, (int)list_indent);
|
|
|
list_tag.tabs = tabs;
|
|
|
-
|
|
|
+ list_tag.size_points = 12*font_scale;
|
|
|
+
|
|
|
item_tag.indent = 0;
|
|
|
- item_tag.left_margin = item_margin;
|
|
|
+ item_tag.left_margin = (int)item_margin;
|
|
|
+
|
|
|
+ if(!reconfiguring) {
|
|
|
+ reconfigure.connect(() => configure_list(level, list_tag, item_tag, true));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public virtual Gtk.TextTag get_blockquote (int level) {
|
|
@@ -198,7 +228,7 @@ namespace GtkCommonMark {
|
|
|
return blockquote_tags.get(level);
|
|
|
}
|
|
|
|
|
|
- protected virtual void configure_blockquote (int level, Gtk.TextTag tag) {
|
|
|
+ protected virtual void configure_blockquote (int level, Gtk.TextTag tag, bool reconfiguring = false) {
|
|
|
const int quote_indent = 9;
|
|
|
const int quote_text_distance = 24;
|
|
|
var quote_margin = ((level+1) * quote_indent) + quote_text_distance;
|
|
@@ -210,10 +240,14 @@ namespace GtkCommonMark {
|
|
|
tabs.set_tab(0, Pango.TabAlign.LEFT, 0);
|
|
|
tabs.set_tab(1, Pango.TabAlign.LEFT, quote_text_distance);
|
|
|
tag.tabs = tabs;
|
|
|
- tag.size_points = 14;
|
|
|
+ tag.size_points = 14 * font_scale;
|
|
|
tag.family = "serif";
|
|
|
tag.foreground = "grey";
|
|
|
tag.accumulative_margin = true;
|
|
|
+
|
|
|
+ if(!reconfiguring) {
|
|
|
+ reconfigure.connect(() => configure_blockquote(level, tag, true));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public virtual Gtk.TextTag get_link (string url) {
|
|
@@ -229,7 +263,14 @@ namespace GtkCommonMark {
|
|
|
protected virtual void configure_link (string url, Gtk.TextTag tag) {
|
|
|
tag.set_data<string>("href", url);
|
|
|
tag.underline = Pango.Underline.SINGLE;
|
|
|
- tag.foreground = "blue";
|
|
|
+ tag.foreground_rgba = link_colour;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void update_link_colour(Gdk.RGBA colour) {
|
|
|
+ link_colour = colour;
|
|
|
+ foreach (var tag in link_tags.values) {
|
|
|
+ tag.foreground_rgba = colour;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|