[gtk/path-ops: 4/4] glyphs: Polish
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/path-ops: 4/4] glyphs: Polish
- Date: Fri, 25 Mar 2022 16:43:55 +0000 (UTC)
commit 67345c2ebd68a08b45092a4f6a3adfdb599c9f85
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 25 11:52:59 2022 -0400
glyphs: Polish
I can't believe its not a font editor.
tests/glyphs.c | 160 +++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 127 insertions(+), 33 deletions(-)
---
diff --git a/tests/glyphs.c b/tests/glyphs.c
index 10a8c6286c..c1dc7ccb8a 100644
--- a/tests/glyphs.c
+++ b/tests/glyphs.c
@@ -36,6 +36,8 @@ struct _DemoWidget
GskPath *short_path;
int short_count;
+
+ GtkTextBuffer *buffer;
};
struct _DemoWidgetClass
@@ -102,6 +104,27 @@ update_short_path (DemoWidget *self)
gtk_widget_queue_draw (GTK_WIDGET (self));
}
+static void
+reset_short_path (DemoWidget *self)
+{
+ self->short_count = 0;
+ update_short_path (self);
+}
+
+static void
+apply_short_path (DemoWidget *self)
+{
+ self->short_count = 10000;
+ update_short_path (self);
+}
+
+static void
+short_path_step (DemoWidget *self)
+{
+ self->short_count++;
+ update_short_path (self);
+}
+
static void
pressed_cb (GtkEventController *controller,
guint keyval,
@@ -112,11 +135,9 @@ pressed_cb (GtkEventController *controller,
DemoWidget *self = (DemoWidget *)gtk_event_controller_get_widget (controller);
if (keyval == GDK_KEY_BackSpace)
- self->short_count = 0;
+ reset_short_path (self);
else
- self->short_count++;
-
- update_short_path (self);
+ short_path_step (self);
}
static void
@@ -277,6 +298,11 @@ demo_widget_snapshot (GtkWidget *widget,
&GRAPHENE_RECT_INIT (0, 0, width, height ));
gtk_snapshot_pop (snapshot);
gsk_stroke_free (stroke);
+ }
+
+ if (1)
+ {
+ GskStroke *stroke;
stroke = gsk_stroke_new (2.0);
gtk_snapshot_push_stroke (snapshot, self->short_path, stroke);
@@ -584,13 +610,26 @@ char_to_path (hb_font_t *font,
return gsk_path_builder_free_to_path (builder);
}
+static char *
+newlineify (char *s)
+{
+ for (char *p = s + 1; *p; p++)
+ {
+ if (strchr ("XZzMmLlHhVvCcSsQqTtOoAaa", *p))
+ p[-1] = '\n';
+ }
+
+ return s;
+}
+
static void
-init_demo (DemoWidget *demo)
+init_demo_from_font (DemoWidget *demo)
{
hb_blob_t *blob;
hb_face_t *face;
hb_font_t *font;
GskPath *path1, *path2;
+ char *s1, *s2, *text;
blob = hb_blob_create_from_file (demo->font_file);
face = hb_face_create (blob, 0);
@@ -603,7 +642,15 @@ init_demo (DemoWidget *demo)
else
path2 = gsk_path_ref (path1);
- demo_widget_set_path (demo, path1, path2);
+ s1 = newlineify (gsk_path_to_string (path1));
+ s2 = newlineify (gsk_path_to_string (path2));
+ text = g_strconcat (s1, "\n\n", s2, NULL);
+
+ gtk_text_buffer_set_text (demo->buffer, text, -1);
+
+ g_free (s1);
+ g_free (s2);
+ g_free (text);
gsk_path_unref (path1);
gsk_path_unref (path2);
@@ -617,7 +664,7 @@ demo_widget_set_font_file (DemoWidget *demo,
{
g_free (demo->font_file);
demo->font_file = g_strdup (file);
- init_demo (demo);
+ init_demo_from_font (demo);
}
static void
@@ -625,7 +672,7 @@ demo_widget_set_text (DemoWidget *demo,
const char *text)
{
demo->text = g_strdup (text);
- init_demo (demo);
+ init_demo_from_font (demo);
}
static void
@@ -766,17 +813,12 @@ text_changed (GtkTextBuffer *buffer,
{
char *text1, *text2;
- g_print ("got two paragraphs\n");
-
text1 = g_strndup (text, p - text);
text2 = g_strdup (p + 2);
path1 = gsk_path_parse (text1);
path2 = gsk_path_parse (text2);
- if (path1 && path2)
- g_print ("got two paths\n");
-
g_free (text1);
g_free (text2);
}
@@ -799,6 +841,23 @@ text_changed (GtkTextBuffer *buffer,
gsk_path_unref (path2);
}
+static const char css_data[] =
+ ".bottombar {"
+ " border-top: 1px solid gray;"
+ " padding: 10px;"
+ " background: none;"
+ " border-spacing: 10px;"
+ "}"
+ ""
+ ".sidebar {"
+ " border-left: 1px solid gray;"
+ " background: none;"
+ "}"
+ ""
+ ".font {"
+ " padding: 10px;"
+ "}";
+
int
main (int argc, char *argv[])
{
@@ -809,13 +868,18 @@ main (int argc, char *argv[])
GtkWidget *zoom_scale;
GtkWidget *hbox, *entry;
GtkWidget *text;
- GtkWidget *paned;
- GtkTextBuffer *buffer;
+ GtkWidget *box3;
+ GtkWidget *box2, *hbox2;
+ GtkCssProvider *style;
gtk_init ();
+ style = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (style, css_data, -1);
+ gtk_style_context_add_provider_for_display (gdk_display_get_default (), GTK_STYLE_PROVIDER (style),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (style);
+
window = gtk_window_new ();
- gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), box);
@@ -824,22 +888,16 @@ main (int argc, char *argv[])
gtk_widget_set_vexpand (demo, TRUE);
sw = gtk_scrolled_window_new ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), demo);
+ gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (sw), TRUE);
+ gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
- paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_paned_set_start_child (GTK_PANED (paned), sw);
- gtk_box_append (GTK_BOX (box), paned);
+ box3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_append (GTK_BOX (box), box3);
+ gtk_box_append (GTK_BOX (box3), sw);
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_add_css_class (hbox, "bottombar");
gtk_box_append (GTK_BOX (box), hbox);
- button = gtk_button_new_with_label ("Cantarell-VF.otf");
- gtk_box_append (GTK_BOX (hbox), button);
-
- g_signal_connect (button, "clicked", G_CALLBACK (filechooser_cb), demo);
- entry = gtk_entry_new ();
- gtk_editable_set_text (GTK_EDITABLE (entry), "KP");
- gtk_editable_set_width_chars (GTK_EDITABLE (entry), 2);
- gtk_box_append (GTK_BOX (hbox), entry);
- g_signal_connect (entry, "activate", G_CALLBACK (activate_entry), demo);
combo = gtk_drop_down_new_from_strings ((const char *[]){ "Original", "Simplified", "Union",
"Intersection", "Difference", "Symmetric Difference", NULL });
g_signal_connect (combo, "notify::selected", G_CALLBACK (operation_changed), demo);
@@ -870,14 +928,50 @@ main (int argc, char *argv[])
g_signal_connect (combo, "notify::selected", G_CALLBACK (fill_rule_changed), demo);
gtk_box_append (GTK_BOX (hbox), combo);
+ button = gtk_button_new_from_icon_name ("edit-redo-symbolic");
+ g_signal_connect_swapped (button, "clicked", G_CALLBACK (apply_short_path), demo);
+ gtk_widget_set_hexpand (button, TRUE);
+ gtk_widget_set_halign (button, GTK_ALIGN_END);
+ gtk_box_append (GTK_BOX (hbox), button);
+
+ button = gtk_button_new_from_icon_name ("list-add-symbolic");
+ g_signal_connect_swapped (button, "clicked", G_CALLBACK (short_path_step), demo);
+ gtk_box_append (GTK_BOX (hbox), button);
+
+ button = gtk_button_new_from_icon_name ("edit-undo-symbolic");
+ g_signal_connect_swapped (button, "clicked", G_CALLBACK (reset_short_path), demo);
+ gtk_box_append (GTK_BOX (hbox), button);
+
+ box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_add_css_class (box2, "sidebar");
+ gtk_widget_set_hexpand (box2, FALSE);
+ gtk_box_append (GTK_BOX (box3), box2);
+
+ hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_add_css_class (hbox2, "font");
+ gtk_widget_add_css_class (hbox2, "linked");
+ gtk_widget_set_halign (hbox2, GTK_ALIGN_CENTER);
+ gtk_box_append (GTK_BOX (box2), hbox2);
+ button = gtk_button_new_with_label ("Cantarell-VF.otf");
+ gtk_box_append (GTK_BOX (hbox2), button);
+ g_signal_connect (button, "clicked", G_CALLBACK (filechooser_cb), demo);
+
+ entry = gtk_entry_new ();
+ gtk_editable_set_text (GTK_EDITABLE (entry), "KP");
+ gtk_editable_set_width_chars (GTK_EDITABLE (entry), 2);
+ gtk_box_append (GTK_BOX (hbox2), entry);
+ g_signal_connect (entry, "activate", G_CALLBACK (activate_entry), demo);
+
sw = gtk_scrolled_window_new ();
text = gtk_text_view_new ();
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
- g_signal_connect (buffer, "changed", G_CALLBACK (text_changed), demo);
+ gtk_widget_set_hexpand (text, TRUE);
+ gtk_widget_set_vexpand (text, TRUE);
+ ((DemoWidget *)demo)->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
+ g_signal_connect (((DemoWidget *)demo)->buffer, "changed", G_CALLBACK (text_changed), demo);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), text);
- gtk_paned_set_end_child (GTK_PANED (paned), sw);
+ gtk_box_append (GTK_BOX (box2), sw);
- init_demo (DEMO_WIDGET (demo));
+ init_demo_from_font (DEMO_WIDGET (demo));
header = gtk_header_bar_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]