pax_global_header00006660000000000000000000000064142201243220014502gustar00rootroot0000000000000052 comment=e2d304e0c81bf0c3138133183a139dcf3da819f1 text-engine-0.1.1/000077500000000000000000000000001422012432200137305ustar00rootroot00000000000000text-engine-0.1.1/.github/000077500000000000000000000000001422012432200152705ustar00rootroot00000000000000text-engine-0.1.1/.github/workflows/000077500000000000000000000000001422012432200173255ustar00rootroot00000000000000text-engine-0.1.1/.github/workflows/c-cpp.yml000066400000000000000000000010161422012432200210500ustar00rootroot00000000000000on: push: branches: [master] pull_request: name: CI jobs: flatpak: name: "Flatpak" runs-on: ubuntu-latest container: image: bilelmoussaoui/flatpak-github-actions:gnome-nightly options: --privileged steps: - uses: actions/checkout@v2 - uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4 with: bundle: bluetype.flatpak manifest-path: com.mattjakeman.TextEngine.Demo.json cache-key: flatpak-builder-${{ github.sha }} run-tests: true text-engine-0.1.1/COPYING000066400000000000000000000167441422012432200147770ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. text-engine-0.1.1/README.md000066400000000000000000000007651422012432200152170ustar00rootroot00000000000000# Text Engine Text Engine is a rich-text editing framework for GTK 4. The primary user of this library is [bluetype](https://github.com/mjakeman/bluetype) but it can be used wherever rich text display and editing is needed. ## Matrix Development of text-engine and bluetype takes place on matrix. Join [#bluetype](https://matrix.to/#/#bluetype:matrix.org) to chat about the project or if you would like to get involved. Come say hello! ## Licence Text Engine is licensed under `LGPL-3.0-or-later`. text-engine-0.1.1/com.mattjakeman.TextEngine.Demo.json000066400000000000000000000023071422012432200226320ustar00rootroot00000000000000{ "app-id" : "com.mattjakeman.TextEngine.Demo", "runtime" : "org.gnome.Platform", "runtime-version" : "master", "sdk" : "org.gnome.Sdk", "command" : "text-engine-demo", "finish-args" : [ "--share=network", "--share=ipc", "--socket=fallback-x11", "--device=dri", "--socket=wayland" ], "cleanup" : [ "/include", "/lib/pkgconfig", "/man", "/share/doc", "/share/gtk-doc", "/share/man", "/share/pkgconfig", "*.la", "*.a" ], "modules" : [ { "name": "blueprint-compiler", "builddir": true, "buildsystem": "meson", "sources": [ { "type": "git", "url": "https://gitlab.gnome.org/jwestman/blueprint-compiler.git", "branch": "main" } ] }, { "name" : "text-engine", "builddir" : true, "buildsystem" : "meson", "sources" : [ { "type" : "dir", "path" : "./" } ] } ] } text-engine-0.1.1/demo/000077500000000000000000000000001422012432200146545ustar00rootroot00000000000000text-engine-0.1.1/demo/demo.c000066400000000000000000000116041422012432200157460ustar00rootroot00000000000000/* demo.c * * Copyright 2022 Matthew Jakeman * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * SPDX-License-Identifier: MIT */ #include #include #include #define DEMO_TYPE_WINDOW demo_window_get_type () G_DECLARE_FINAL_TYPE (DemoWindow, demo_window, DEMO, WINDOW, AdwApplicationWindow) struct _DemoWindow { AdwApplicationWindow parent_instance; }; G_DEFINE_FINAL_TYPE (DemoWindow, demo_window, ADW_TYPE_APPLICATION_WINDOW) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; static void demo_window_finalize (GObject *object) { DemoWindow *self = (DemoWindow *)object; G_OBJECT_CLASS (demo_window_parent_class)->finalize (object); } static void demo_window_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { DemoWindow *self = DEMO_WINDOW (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void demo_window_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { DemoWindow *self = DEMO_WINDOW (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void demo_window_class_init (DemoWindowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = demo_window_finalize; object_class->get_property = demo_window_get_property; object_class->set_property = demo_window_set_property; } static void demo_window_init (DemoWindow *self) { TextFrame *frame; TextDisplay *display; const gchar *test; GtkWidget *header_bar; GtkWidget *vbox; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); adw_application_window_set_content (ADW_APPLICATION_WINDOW (self), vbox); // Example rich text document (uses html subset) test = "

There was an Old Man with a beard\nWho said, "It is just as I feared!

> Two Owls and a Hen,
> Four Larks and a Wren,

Have all built their nests in my beard!"

"; frame = format_parse_html (test); header_bar = adw_header_bar_new (); display = text_display_new (frame); gtk_box_append (GTK_BOX (vbox), header_bar); gtk_box_append (GTK_BOX (vbox), GTK_WIDGET (display)); } static void demo_activate (GApplication *app) { GtkWindow *window; g_assert (G_IS_APPLICATION (app)); // Add CSS Stylesheet GtkCssProvider *css_provider = gtk_css_provider_new (); gtk_css_provider_load_from_resource (css_provider, "/com/mattjakeman/TextEngine/Demo/style.css"); GdkDisplay *display = gdk_display_get_default (); gtk_style_context_add_provider_for_display (display, GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); // Get the current window or create one if necessary. window = gtk_application_get_active_window (GTK_APPLICATION (app)); if (window == NULL) window = g_object_new (DEMO_TYPE_WINDOW, "application", app, "default-width", 500, "default-height", 500, NULL); // Ask the window manager/compositor to present the window. gtk_window_present (window); } int main (int argc, char **argv) { AdwApplication *app; int ret; app = adw_application_new ("com.mattjakeman.TextEngine.Demo", G_APPLICATION_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (demo_activate), NULL); ret = g_application_run (G_APPLICATION (app), argc, argv); g_clear_object (&app); return ret; } text-engine-0.1.1/demo/meson.build000066400000000000000000000005211422012432200170140ustar00rootroot00000000000000demo_sources = [ 'demo.c' ] demo_deps = [ text_engine_dep, dependency('libadwaita-1') ] gnome = import('gnome') demo_sources += gnome.compile_resources('resources', 'resources.gresource.xml', source_dir: '.', c_name: 'resources' ) executable('text-engine-demo', demo_sources, dependencies: demo_deps, install: true, ) text-engine-0.1.1/demo/resources.gresource.xml000066400000000000000000000002441422012432200214050ustar00rootroot00000000000000 style.css text-engine-0.1.1/demo/style.css000066400000000000000000000000001422012432200165140ustar00rootroot00000000000000text-engine-0.1.1/meson.build000066400000000000000000000007421422012432200160750ustar00rootroot00000000000000project('text-engine', 'c', version: '0.1.0', meson_version: '>= 0.50.0', default_options: [ 'warning_level=2', 'c_std=gnu11', ], ) config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) configure_file( output: 'text-engine-config.h', configuration: config_h, ) add_project_arguments([ '-I' + meson.build_root(), ], language: 'c') subdir('src') subdir('demo') subdir('test') text-engine-0.1.1/src/000077500000000000000000000000001422012432200145175ustar00rootroot00000000000000text-engine-0.1.1/src/format/000077500000000000000000000000001422012432200160075ustar00rootroot00000000000000text-engine-0.1.1/src/format/import-html.c000066400000000000000000000063551422012432200204400ustar00rootroot00000000000000/* import-html.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "import.h" #include #include #include "../model/paragraph.h" #include "../model/block.h" #include "../model/run.h" static void build_text_frame_recursive (xmlNode *nodes, TextFrame *frame, TextParagraph **current) { g_return_if_fail (TEXT_IS_FRAME (frame)); g_return_if_fail (current); xmlNode *cur_node = NULL; if (nodes == NULL) return; for (cur_node = nodes; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { if (g_str_equal (cur_node->name, "p") || g_str_equal (cur_node->name, "br")) { *current = text_paragraph_new (); text_frame_append_block (frame, TEXT_BLOCK (*current)); } else { // Catch-all for not-yet implemented elements g_print ("Ignored element %s\n", cur_node->name); } } else if (cur_node->type == XML_TEXT_NODE) { // Append text as new run const gchar *content = (gchar *)cur_node->content; text_paragraph_append_run (*current, text_run_new (content)); } build_text_frame_recursive (cur_node->children, frame, current); } } /** * build_text_frame: * @nodes: Array of #xmlNode structures to parse * @frame: An initialised #TextFrame to populate with data * * Recursively builds a new #TextFrame and populates it with data * from the provided normalised HTML tree. */ static void build_text_frame (xmlNode *nodes, TextFrame *frame) { TextParagraph *current = NULL; build_text_frame_recursive (nodes, frame, ¤t); } TextFrame * format_parse_html (const gchar *html) { htmlDocPtr doc; xmlNode *root; TextFrame *frame; g_print ("%s\n", html); doc = htmlParseDoc ((const guchar *)html, "utf-8"); if (doc == NULL) { g_critical ("Could not parse HTML document."); return NULL; } root = xmlDocGetRootElement (doc); if (root == NULL) { g_warning ("Empty HTML document."); xmlFreeDoc (doc); xmlCleanupParser (); return NULL; } frame = text_frame_new (); g_print ("Root Node discovered: %s\n", root->name); build_text_frame (root, frame); xmlFreeDoc (doc); xmlCleanupParser (); return frame; } text-engine-0.1.1/src/format/import.h000066400000000000000000000016461422012432200175010ustar00rootroot00000000000000/* import.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "../model/frame.h" G_BEGIN_DECLS TextFrame *format_parse_html (const gchar *html); G_END_DECLS text-engine-0.1.1/src/format/meson.build000066400000000000000000000002321422012432200201460ustar00rootroot00000000000000text_engine_sources += files([ 'import-html.c', ]) format_headers = [ 'import.h', ] install_headers(format_headers, subdir : header_dir / 'format') text-engine-0.1.1/src/layout/000077500000000000000000000000001422012432200160345ustar00rootroot00000000000000text-engine-0.1.1/src/layout/README.md000066400000000000000000000013621422012432200173150ustar00rootroot00000000000000# Layout This is the default layout engine. It is a layout policy used to transform the semantic text model into a format that can be displayed. Custom layouts can be implemented (not now, in the future) by subclassing `TextLayout` and overriding select virtual methods. The 'layout manager' takes in a 'semantic tree' and produces a 'layout tree', which is passed on the toolkit-specific drawing widget. It is responsible for caching the layout tree in between redraws and minimising the recomputation needed. The architecture of the layout tree is loosely inspired by Matt Brubeck's [excellent series](https://limpet.net/mbrubeck/2014/09/08/toy-layout-engine-5-boxes.html) on building a browser engine, itself a simplification of modern web engines. text-engine-0.1.1/src/layout/layout-box.c000066400000000000000000000137441422012432200203140ustar00rootroot00000000000000/* layout-box.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "layout-box.h" #include "../model/paragraph.h" #include "../tree/node.h" typedef struct { TextItem *item; PangoLayout *layout; TextDimensions bbox; } TextLayoutBoxPrivate; G_DEFINE_FINAL_TYPE_WITH_PRIVATE (TextLayoutBox, text_layout_box, TEXT_TYPE_NODE) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; /** * text_layout_box_new: * * Create a new #TextLayoutBox. * * Returns: (transfer full): a newly created #TextLayoutBox */ TextLayoutBox * text_layout_box_new (void) { return g_object_new (TEXT_TYPE_LAYOUT_BOX, NULL); } static void text_layout_box_finalize (GObject *object) { TextLayoutBox *self = (TextLayoutBox *)object; TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (self); // Dispose of children for (TextNode *child = text_node_get_first_child (TEXT_NODE (self)); child != NULL; child = text_node_get_next (TEXT_NODE (self))) { g_clear_object (&child); } G_OBJECT_CLASS (text_layout_box_parent_class)->finalize (object); } static void text_layout_box_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextLayoutBox *self = TEXT_LAYOUT_BOX (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_layout_box_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextLayoutBox *self = TEXT_LAYOUT_BOX (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } void text_layout_box_layout (TextLayoutBox *self, PangoContext *context, int width) { g_return_if_fail (TEXT_IS_LAYOUT_BOX (self)); TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (self); int height = 0; g_debug ("Starting for %s\n", g_type_name_from_instance (self)); g_debug ("Has item: %d\n", priv->item != NULL); g_debug ("Has paragraph: %d\n", TEXT_IS_PARAGRAPH (priv->item)); if (priv->item && TEXT_IS_PARAGRAPH (priv->item)) { GString *str = g_string_new (""); for (TextNode *run = text_node_get_first_child (TEXT_NODE (priv->item)); run != NULL; run = text_node_get_next (run)) { const gchar *run_text; g_object_get (run, "text", &run_text, NULL); g_string_append (str, run_text); g_debug (" - Counting run\n"); } gchar *text = g_string_free (str, FALSE); g_debug (" - String %s\n", text); if (!priv->layout) priv->layout = pango_layout_new (context); pango_layout_set_text (priv->layout, text, -1); pango_layout_set_wrap (priv->layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_width (priv->layout, PANGO_SCALE * width); pango_layout_get_pixel_size (priv->layout, NULL, &height); g_debug (" - Height %d\n", height); g_free (text); } // Account for children (should we force elements to choose between // children and text? seems like a sensible simplification) for (TextNode *node = text_node_get_first_child (TEXT_NODE (self)); node != NULL; node = text_node_get_next (node)) { TextLayoutBox *child_box = TEXT_LAYOUT_BOX (node); g_debug (" - Found child\n"); // We can assume bbox already exists by now, as the layout() method // has been called already in the layout manager. TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (child_box); height += priv->bbox.height; g_debug (" - Child height %d\n", height); } priv->bbox.x = 0; priv->bbox.y = 0; priv->bbox.width = width; priv->bbox.height = height; } void text_layout_box_set_item (TextLayoutBox *self, TextItem *item) { TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (self); priv->item = item; g_debug ("Set item to non null: %d\n", priv->item != NULL); } TextItem * text_layout_box_get_item (TextLayoutBox *self, TextItem *item) { TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (self); return priv->item; } const TextDimensions * text_layout_box_get_bbox (TextLayoutBox *self) { TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (self); return &priv->bbox; } PangoLayout * text_layout_box_get_pango_layout (TextLayoutBox *self) { TextLayoutBoxPrivate *priv = text_layout_box_get_instance_private (self); return priv->layout; } static void text_layout_box_class_init (TextLayoutBoxClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_layout_box_finalize; object_class->get_property = text_layout_box_get_property; object_class->set_property = text_layout_box_set_property; } static void text_layout_box_init (TextLayoutBox *self) { } text-engine-0.1.1/src/layout/layout-box.h000066400000000000000000000032641422012432200203150ustar00rootroot00000000000000/* layout-box.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include #include "../tree/node.h" #include "../model/item.h" #include "types.h" G_BEGIN_DECLS #define TEXT_TYPE_LAYOUT_BOX (text_layout_box_get_type()) G_DECLARE_DERIVABLE_TYPE (TextLayoutBox, text_layout_box, TEXT, LAYOUT_BOX, TextNode) struct _TextLayoutBoxClass { TextNodeClass parent_class; }; TextLayoutBox *text_layout_box_new (void); void text_layout_box_set_item (TextLayoutBox *self, TextItem *item); TextItem * text_layout_box_get_item (TextLayoutBox *self, TextItem *item); void text_layout_box_layout (TextLayoutBox *self, PangoContext *context, int width); const TextDimensions * text_layout_box_get_bbox (TextLayoutBox *self); PangoLayout * text_layout_box_get_pango_layout (TextLayoutBox *self); G_END_DECLS text-engine-0.1.1/src/layout/layout.c000066400000000000000000000104401422012432200175140ustar00rootroot00000000000000/* layout.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "layout.h" struct _TextLayout { GObject parent_instance; }; G_DEFINE_FINAL_TYPE (TextLayout, text_layout, G_TYPE_OBJECT) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; TextLayout * text_layout_new (void) { return g_object_new (TEXT_TYPE_LAYOUT, NULL); } static void text_layout_finalize (GObject *object) { TextLayout *self = (TextLayout *)object; G_OBJECT_CLASS (text_layout_parent_class)->finalize (object); } static void text_layout_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextLayout *self = TEXT_LAYOUT (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_layout_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextLayout *self = TEXT_LAYOUT (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void do_layout_recursive (TextLayout *self, TextLayoutBox *parent, PangoContext *context, TextItem *item, int width) { g_return_if_fail (TEXT_IS_LAYOUT (self)); g_return_if_fail (TEXT_IS_LAYOUT_BOX (parent)); g_return_if_fail (TEXT_IS_ITEM (item)); // Append children (in future, recursively) for (TextNode *node = text_node_get_first_child (TEXT_NODE (item)); node != NULL; node = text_node_get_next (node)) { g_assert (TEXT_IS_ITEM (node)); g_debug ("Counting child %s\n", g_type_name_from_instance (node)); // Let's treat paragraphs opaquely for now. In the future, we need // to manually consider each text run in order for inline equations // and images. if (TEXT_IS_PARAGRAPH (node)) { TextLayoutBox *box = text_layout_box_new (); text_layout_box_set_item (box, TEXT_ITEM (node)); text_node_append_child (TEXT_NODE (parent), TEXT_NODE (box)); g_debug ("Added child %s\n", g_type_name_from_instance (node)); // TODO: This function should be properly recursive in the future, // so avoid calling it here. Below should be the only time it is // called (i.e. post-order traversal). text_layout_box_layout (box, context, width); } } text_layout_box_layout (parent, context, width); g_debug ("Layout for %s\n", g_type_name_from_instance (parent)); } TextLayoutBox * text_layout_build_layout_tree (TextLayout *self, PangoContext *context, TextFrame *frame, int width) { g_return_if_fail (TEXT_IS_LAYOUT (self)); g_return_if_fail (TEXT_IS_FRAME (frame)); TextLayoutBox *root = text_layout_box_new (); do_layout_recursive (self, root, context, TEXT_ITEM (frame), width); return root; } static void text_layout_class_init (TextLayoutClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_layout_finalize; object_class->get_property = text_layout_get_property; object_class->set_property = text_layout_set_property; } static void text_layout_init (TextLayout *self) { } text-engine-0.1.1/src/layout/layout.h000066400000000000000000000025441422012432200175270ustar00rootroot00000000000000/* layout.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include #include #include "layout-box.h" #include "../model/frame.h" #include "../model/paragraph.h" G_BEGIN_DECLS #define TEXT_TYPE_LAYOUT (text_layout_get_type()) G_DECLARE_FINAL_TYPE (TextLayout, text_layout, TEXT, LAYOUT, GObject) TextLayout *text_layout_new (void); TextLayoutBox * text_layout_build_layout_tree (TextLayout *self, PangoContext *context, TextFrame *frame, int width); G_END_DECLS text-engine-0.1.1/src/layout/meson.build000066400000000000000000000003041422012432200201730ustar00rootroot00000000000000text_engine_sources += files([ 'layout.c', 'layout-box.c' ]) layout_headers = [ 'layout.h', 'layout-box.h', 'types.h' ] install_headers(layout_headers, subdir : header_dir / 'layout') text-engine-0.1.1/src/layout/types.h000066400000000000000000000020101422012432200173420ustar00rootroot00000000000000/* types.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ /* TODO: Make these GBoxed for introspection support! */ #include typedef struct { gdouble x; gdouble y; gdouble width; gdouble height; // TODO: Also consider padding/margin/border? } TextDimensions; text-engine-0.1.1/src/meson.build000066400000000000000000000032501422012432200166610ustar00rootroot00000000000000api_version = '0.1' header_dir = 'text-engine' text_engine_sources = [ 'text-engine.c', ] text_engine_headers = [ 'text-engine.h', ] # Utility subdir('format') # Trees subdir('tree') subdir('model') subdir('layout') subdir('ui') version_split = meson.project_version().split('.') MAJOR_VERSION = version_split[0] MINOR_VERSION = version_split[1] MICRO_VERSION = version_split[2] version_conf = configuration_data() version_conf.set('VERSION', meson.project_version()) version_conf.set('MAJOR_VERSION', MAJOR_VERSION) version_conf.set('MINOR_VERSION', MINOR_VERSION) version_conf.set('MICRO_VERSION', MICRO_VERSION) configure_file( input: 'text-engine-version.h.in', output: 'text-engine-version.h', configuration: version_conf, install: true, install_dir: join_paths(get_option('includedir'), header_dir) ) text_engine_deps = [ dependency('gio-2.0', version: '>= 2.50'), dependency('json-glib-1.0'), dependency('libxml-2.0'), dependency('gtk4') ] text_engine_lib = shared_library('text-engine-' + api_version, text_engine_sources, dependencies: text_engine_deps, install: true, ) install_headers(text_engine_headers, subdir: header_dir) text_engine_dep = declare_dependency( link_with: text_engine_lib, include_directories: include_directories('.'), dependencies: text_engine_deps, # sources: resources ) pkg = import('pkgconfig') pkg.generate( description: 'A shared library for ...', libraries: text_engine_lib, name: 'text-engine', filebase: 'text-engine-' + api_version, version: meson.project_version(), subdirs: 'text-engine', requires: 'glib-2.0', install_dir: join_paths(get_option('libdir'), 'pkgconfig') ) text-engine-0.1.1/src/model/000077500000000000000000000000001422012432200156175ustar00rootroot00000000000000text-engine-0.1.1/src/model/README.md000066400000000000000000000002161422012432200170750ustar00rootroot00000000000000# Model This is the text engine document model. It is a platform agnostic representation of a rich text document using a tree-like structure. text-engine-0.1.1/src/model/block.c000066400000000000000000000044051422012432200170600ustar00rootroot00000000000000/* block.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "block.h" typedef struct { int _padding; } TextBlockPrivate; G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TextBlock, text_block, TEXT_TYPE_ITEM) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; static void text_block_finalize (GObject *object) { TextBlock *self = (TextBlock *)object; TextBlockPrivate *priv = text_block_get_instance_private (self); G_OBJECT_CLASS (text_block_parent_class)->finalize (object); } static void text_block_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextBlock *self = TEXT_BLOCK (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_block_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextBlock *self = TEXT_BLOCK (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_block_class_init (TextBlockClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_block_finalize; object_class->get_property = text_block_get_property; object_class->set_property = text_block_set_property; } static void text_block_init (TextBlock *self) { } text-engine-0.1.1/src/model/block.h000066400000000000000000000020461422012432200170640ustar00rootroot00000000000000/* block.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "item.h" G_BEGIN_DECLS #define TEXT_TYPE_BLOCK (text_block_get_type()) G_DECLARE_DERIVABLE_TYPE (TextBlock, text_block, TEXT, BLOCK, TextItem) struct _TextBlockClass { TextNodeClass parent_class; }; G_END_DECLS text-engine-0.1.1/src/model/frame.c000066400000000000000000000057311422012432200170630ustar00rootroot00000000000000/* frame.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "frame.h" typedef struct { int _padding; } TextFramePrivate; G_DEFINE_FINAL_TYPE_WITH_PRIVATE (TextFrame, text_frame, TEXT_TYPE_BLOCK) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; /** * text_frame_new: * * Create a new #TextFrame. * * Returns: (transfer full): a newly created #TextFrame */ TextFrame * text_frame_new (void) { return g_object_new (TEXT_TYPE_FRAME, NULL); } static void text_frame_finalize (GObject *object) { TextFrame *self = (TextFrame *)object; TextFramePrivate *priv = text_frame_get_instance_private (self); G_OBJECT_CLASS (text_frame_parent_class)->finalize (object); } static void text_frame_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextFrame *self = TEXT_FRAME (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_frame_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextFrame *self = TEXT_FRAME (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } void text_frame_append_block (TextFrame *self, TextBlock *block) { g_return_if_fail (TEXT_IS_FRAME (self)); g_return_if_fail (TEXT_IS_BLOCK (block)); text_node_append_child (TEXT_NODE (self), TEXT_NODE (block)); } void text_frame_prepend_block (TextFrame *self, TextBlock *block) { g_return_if_fail (TEXT_IS_FRAME (self)); g_return_if_fail (TEXT_IS_BLOCK (block)); text_node_prepend_child (TEXT_NODE (self), TEXT_NODE (block)); } static void text_frame_class_init (TextFrameClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_frame_finalize; object_class->get_property = text_frame_get_property; object_class->set_property = text_frame_set_property; } static void text_frame_init (TextFrame *self) { } text-engine-0.1.1/src/model/frame.h000066400000000000000000000023721422012432200170660ustar00rootroot00000000000000/* frame.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "item.h" #include "block.h" G_BEGIN_DECLS #define TEXT_TYPE_FRAME (text_frame_get_type()) G_DECLARE_DERIVABLE_TYPE (TextFrame, text_frame, TEXT, FRAME, TextBlock) struct _TextFrameClass { TextBlockClass parent_class; }; TextFrame *text_frame_new (void); void text_frame_append_block (TextFrame *self, TextBlock *block); void text_frame_prepend_block (TextFrame *self, TextBlock *block); G_END_DECLS text-engine-0.1.1/src/model/item.c000066400000000000000000000044521422012432200167260ustar00rootroot00000000000000/* item.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "item.h" G_DEFINE_TYPE (TextItem, text_item, TEXT_TYPE_NODE) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; /** * text_item_new: * * Create a new #TextItem. * * Returns: (transfer full): a newly created #TextItem */ TextItem * text_item_new (void) { return g_object_new (TEXT_TYPE_ITEM, NULL); } static void text_item_finalize (GObject *object) { TextItem *self = (TextItem *)object; G_OBJECT_CLASS (text_item_parent_class)->finalize (object); } static void text_item_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextItem *self = TEXT_ITEM (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextItem *self = TEXT_ITEM (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_item_class_init (TextItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_item_finalize; object_class->get_property = text_item_get_property; object_class->set_property = text_item_set_property; } static void text_item_init (TextItem *self) { } text-engine-0.1.1/src/model/item.h000066400000000000000000000021071422012432200167260ustar00rootroot00000000000000/* item.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "../tree/node.h" G_BEGIN_DECLS #define TEXT_TYPE_ITEM (text_item_get_type()) G_DECLARE_DERIVABLE_TYPE (TextItem, text_item, TEXT, ITEM, TextNode) struct _TextItemClass { TextNodeClass parent_class; }; TextItem *text_item_new (void); G_END_DECLS text-engine-0.1.1/src/model/meson.build000066400000000000000000000003701422012432200177610ustar00rootroot00000000000000text_engine_sources += files([ 'item.c', 'run.c', 'block.c', 'frame.c', 'paragraph.c' ]) model_headers = [ 'item.h', 'run.h', 'block.h', 'frame.h', 'paragraph.h' ] install_headers(model_headers, subdir : header_dir / 'model') text-engine-0.1.1/src/model/paragraph.c000066400000000000000000000052251422012432200177340ustar00rootroot00000000000000/* paragraph.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "paragraph.h" struct _TextParagraph { TextBlock parent_instance; }; G_DEFINE_FINAL_TYPE (TextParagraph, text_paragraph, TEXT_TYPE_BLOCK) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; TextParagraph * text_paragraph_new (void) { return g_object_new (TEXT_TYPE_PARAGRAPH, NULL); } static void text_paragraph_finalize (GObject *object) { TextParagraph *self = (TextParagraph *)object; G_OBJECT_CLASS (text_paragraph_parent_class)->finalize (object); } static void text_paragraph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextParagraph *self = TEXT_PARAGRAPH (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_paragraph_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextParagraph *self = TEXT_PARAGRAPH (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } void text_paragraph_append_run (TextParagraph *self, TextRun *run) { g_return_if_fail (TEXT_IS_PARAGRAPH (self)); g_return_if_fail (TEXT_IS_RUN (run)); text_node_append_child (TEXT_NODE (self), TEXT_NODE (run)); } static void text_paragraph_class_init (TextParagraphClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_paragraph_finalize; object_class->get_property = text_paragraph_get_property; object_class->set_property = text_paragraph_set_property; } static void text_paragraph_init (TextParagraph *self) { } text-engine-0.1.1/src/model/paragraph.h000066400000000000000000000022421422012432200177350ustar00rootroot00000000000000/* paragraph.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "item.h" #include "block.h" #include "run.h" G_BEGIN_DECLS #define TEXT_TYPE_PARAGRAPH (text_paragraph_get_type()) G_DECLARE_FINAL_TYPE (TextParagraph, text_paragraph, TEXT, PARAGRAPH, TextBlock) TextParagraph *text_paragraph_new (void); void text_paragraph_append_run (TextParagraph *para, TextRun *run); G_END_DECLS text-engine-0.1.1/src/model/run.c000066400000000000000000000055351422012432200165770ustar00rootroot00000000000000/* run.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "run.h" struct _TextRun { TextItem parent_instance; gchar *text; }; G_DEFINE_FINAL_TYPE (TextRun, text_run, TEXT_TYPE_ITEM) enum { PROP_0, PROP_TEXT, N_PROPS }; static GParamSpec *properties [N_PROPS]; TextRun * text_run_new (const gchar *text) { return g_object_new (TEXT_TYPE_RUN, "text", text, NULL); } static void text_run_finalize (GObject *object) { TextRun *self = (TextRun *)object; G_OBJECT_CLASS (text_run_parent_class)->finalize (object); } static void text_run_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextRun *self = TEXT_RUN (object); switch (prop_id) { case PROP_TEXT: g_value_set_string (value, self->text); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_run_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextRun *self = TEXT_RUN (object); switch (prop_id) { case PROP_TEXT: if (self->text) g_free (self->text); self->text = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_run_class_init (TextRunClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_run_finalize; object_class->get_property = text_run_get_property; object_class->set_property = text_run_set_property; properties [PROP_TEXT] = g_param_spec_string ("text", "Text", "Text", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT); g_object_class_install_properties (object_class, N_PROPS, properties); } static void text_run_init (TextRun *self) { } text-engine-0.1.1/src/model/run.h000066400000000000000000000020051422012432200165710ustar00rootroot00000000000000/* run.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "item.h" G_BEGIN_DECLS #define TEXT_TYPE_RUN (text_run_get_type()) G_DECLARE_FINAL_TYPE (TextRun, text_run, TEXT, RUN, TextItem) TextRun *text_run_new (const gchar *text); G_END_DECLS text-engine-0.1.1/src/text-engine-version.h.in000066400000000000000000000055631422012432200212200ustar00rootroot00000000000000/* text-engine-version.h.in * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #if !defined(TEXT_ENGINE_INSIDE) && !defined(TEXT_ENGINE_COMPILATION) # error "Only can be included directly." #endif /** * SECTION:text_engineversion * @short_description: text-engine version checking * * text-engine provides macros to check the version of the library * at compile-time */ /** * TEXT_ENGINE_MAJOR_VERSION: * * text-engine major version component (e.g. 1 if %TEXT_ENGINE_VERSION is 1.2.3) */ #define TEXT_ENGINE_MAJOR_VERSION (@MAJOR_VERSION@) /** * TEXT_ENGINE_MINOR_VERSION: * * text-engine minor version component (e.g. 2 if %TEXT_ENGINE_VERSION is 1.2.3) */ #define TEXT_ENGINE_MINOR_VERSION (@MINOR_VERSION@) /** * TEXT_ENGINE_MICRO_VERSION: * * text-engine micro version component (e.g. 3 if %TEXT_ENGINE_VERSION is 1.2.3) */ #define TEXT_ENGINE_MICRO_VERSION (@MICRO_VERSION@) /** * TEXT_ENGINE_VERSION * * text-engine version. */ #define TEXT_ENGINE_VERSION (@VERSION@) /** * TEXT_ENGINE_VERSION_S: * * text-engine version, encoded as a string, useful for printing and * concatenation. */ #define TEXT_ENGINE_VERSION_S "@VERSION@" #define TEXT_ENGINE_ENCODE_VERSION(major,minor,micro) \ ((major) << 24 | (minor) << 16 | (micro) << 8) /** * TEXT_ENGINE_VERSION_HEX: * * text-engine version, encoded as an hexadecimal number, useful for * integer comparisons. */ #define TEXT_ENGINE_VERSION_HEX \ (TEXT_ENGINE_ENCODE_VERSION (TEXT_ENGINE_MAJOR_VERSION, TEXT_ENGINE_MINOR_VERSION, TEXT_ENGINE_MICRO_VERSION)) /** * TEXT_ENGINE_CHECK_VERSION: * @major: required major version * @minor: required minor version * @micro: required micro version * * Compile-time version checking. Evaluates to %TRUE if the version * of text-engine is greater than the required one. */ #define TEXT_ENGINE_CHECK_VERSION(major,minor,micro) \ (TEXT_ENGINE_MAJOR_VERSION > (major) || \ (TEXT_ENGINE_MAJOR_VERSION == (major) && TEXT_ENGINE_MINOR_VERSION > (minor)) || \ (TEXT_ENGINE_MAJOR_VERSION == (major) && TEXT_ENGINE_MINOR_VERSION == (minor) && \ TEXT_ENGINE_MICRO_VERSION >= (micro))) text-engine-0.1.1/src/text-engine.c000066400000000000000000000014711422012432200171150ustar00rootroot00000000000000/* text-engine.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "text-engine.h" text-engine-0.1.1/src/text-engine.h000066400000000000000000000016631422012432200171250ustar00rootroot00000000000000/* text-engine.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include G_BEGIN_DECLS #define TEXT_ENGINE_INSIDE # include "text-engine-version.h" #undef TEXT_ENGINE_INSIDE G_END_DECLS text-engine-0.1.1/src/tree/000077500000000000000000000000001422012432200154565ustar00rootroot00000000000000text-engine-0.1.1/src/tree/README.md000066400000000000000000000002231422012432200167320ustar00rootroot00000000000000# Tree A flexible tree/graph implementation. Used by the model and layout stages to create and update intermediary trees in the rendering process. text-engine-0.1.1/src/tree/meson.build000066400000000000000000000002131422012432200176140ustar00rootroot00000000000000text_engine_sources += files([ 'node.c', ]) tree_headers = [ 'node.h', ] install_headers(tree_headers, subdir : header_dir / 'tree') text-engine-0.1.1/src/tree/node.c000066400000000000000000000160271422012432200165550ustar00rootroot00000000000000/* node.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "node.h" typedef struct { TextNode *parent; TextNode *prev; TextNode *next; TextNode *first_child; TextNode *last_child; int n_children; } TextNodePrivate; G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TextNode, text_node, G_TYPE_OBJECT) enum { PROP_0, N_PROPS }; static GParamSpec *properties [N_PROPS]; /** * text_node_new: * * Create a new #TextNode. * * Returns: (transfer full): a newly created #TextNode */ TextNode * text_node_new (void) { return g_object_new (TEXT_TYPE_NODE, NULL); } static void text_node_finalize (GObject *object) { TextNode *self = (TextNode *)object; TextNodePrivate *priv = text_node_get_instance_private (self); G_OBJECT_CLASS (text_node_parent_class)->finalize (object); } static void text_node_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextNode *self = TEXT_NODE (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_node_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextNode *self = TEXT_NODE (object); switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } TextNode * text_node_get_first_child (TextNode *self) { TextNodePrivate *priv = text_node_get_instance_private (self); return priv->first_child; } TextNode * text_node_get_last_child (TextNode *self) { TextNodePrivate *priv = text_node_get_instance_private (self); return priv->last_child; } TextNode * text_node_get_previous (TextNode *self) { TextNodePrivate *priv = text_node_get_instance_private (self); return priv->prev; } TextNode * text_node_get_next (TextNode *self) { TextNodePrivate *priv = text_node_get_instance_private (self); return priv->next; } TextNode * text_node_get_parent (TextNode *self) { TextNodePrivate *priv = text_node_get_instance_private (self); return priv->parent; } static void _insert_between (TextNode *node, TextNode *before, TextNode *after) { TextNodePrivate *node_priv, *before_priv, *after_priv; g_assert (node != NULL); g_assert (before != NULL); g_assert (after != NULL); node_priv = text_node_get_instance_private (node); before_priv = text_node_get_instance_private (before); after_priv = text_node_get_instance_private (after); node_priv->prev = before; before_priv->next = node; node_priv->next = after; after_priv->prev = node; } static int _get_index_of (TextNode *self, TextNode *child) { TextNode *iter; int index; index = 0; for (iter = text_node_get_first_child (self); iter != NULL; iter = text_node_get_next (self)) { if (iter == child) return index; index++; } return -1; } void text_node_insert_child (TextNode *self, TextNode *child, int index) { int cmp_index; TextNode *before, *after, *iter; TextNodePrivate *priv, *child_priv, *before_priv, *after_priv; priv = text_node_get_instance_private (self); child_priv = text_node_get_instance_private (child); g_assert (index >= 0 && index <= priv->n_children); g_object_ref_sink (child); // No children if (priv->n_children == 0) { priv->first_child = child; priv->last_child = child; priv->n_children = 1; return; } // Prepend if (index == 0) { after = priv->first_child; after_priv = text_node_get_instance_private (after); after_priv->prev = child; child_priv->next = after; priv->first_child = child; priv->n_children++; return; } // Append if (index == priv->n_children) { before = priv->last_child; before_priv = text_node_get_instance_private (before); before_priv->next = child; child_priv->prev = before; priv->last_child = child; priv->n_children++; return; } // Insert (After) cmp_index = 0; iter = text_node_get_first_child (self); while (cmp_index++ < index) { iter = text_node_get_next (iter); g_assert (iter != NULL); } _insert_between (child, iter, text_node_get_next (iter)); } void text_node_prepend_child (TextNode *self, TextNode *child) { text_node_insert_child (self, child, 0); } void text_node_append_child (TextNode *self, TextNode *child) { TextNodePrivate *priv = text_node_get_instance_private (self); text_node_insert_child (self, child, priv->n_children); } void text_node_insert_child_before (TextNode *self, TextNode *child, TextNode *compare) { int index; index = _get_index_of (self, compare); if (index == -1) { g_critical ("Provided compare node is not a child of this text node."); return; } if ((index - 1) == 0) { g_object_ref_sink (child); text_node_prepend_child (self, child); return; } text_node_insert_child (self, child, index-1); } void text_node_insert_child_after (TextNode *self, TextNode *child, TextNode *compare) { int index; index = _get_index_of (self, compare); if (index == -1) { g_critical ("Provided compare node is not a child of this text node."); return; } text_node_insert_child (self, child, index); } static void text_node_class_init (TextNodeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_node_finalize; object_class->get_property = text_node_get_property; object_class->set_property = text_node_set_property; } static void text_node_init (TextNode *self) { TextNodePrivate *priv = text_node_get_instance_private (self); priv->first_child = NULL; priv->last_child = NULL; priv->n_children = 0; } text-engine-0.1.1/src/tree/node.h000066400000000000000000000033531422012432200165600ustar00rootroot00000000000000/* node.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include G_BEGIN_DECLS #define TEXT_TYPE_NODE (text_node_get_type()) G_DECLARE_DERIVABLE_TYPE (TextNode, text_node, TEXT, NODE, GObject) struct _TextNodeClass { GObjectClass parent_class; }; // Implementors Only TextNode *text_node_get_parent (TextNode *self); TextNode *text_node_get_next (TextNode *self); TextNode *text_node_get_previous (TextNode *self); TextNode *text_node_get_first_child (TextNode *self); TextNode *text_node_get_last_child (TextNode *self); void text_node_insert_child (TextNode *self, TextNode *child, int index); void text_node_prepend_child (TextNode *self, TextNode *child); void text_node_append_child (TextNode *self, TextNode *child); void text_node_insert_child_before (TextNode *self, TextNode *child, TextNode *compare); void text_node_insert_child_after (TextNode *self, TextNode *child, TextNode *compare); G_END_DECLS text-engine-0.1.1/src/ui/000077500000000000000000000000001422012432200151345ustar00rootroot00000000000000text-engine-0.1.1/src/ui/display.c000066400000000000000000000166361422012432200167610ustar00rootroot00000000000000/* display.c * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "display.h" #include "../model/paragraph.h" #include "../layout/layout.h" struct _TextDisplay { GtkWidget parent_instance; TextFrame *frame; TextLayout *layout; TextLayoutBox *layout_tree; }; G_DEFINE_FINAL_TYPE (TextDisplay, text_display, GTK_TYPE_WIDGET) enum { PROP_0, PROP_FRAME, N_PROPS }; static GParamSpec *properties [N_PROPS]; /** * text_display_new: * @frame: The #TextFrame to display or %NULL * * Creates a new #TextDisplay widget which displays the rich text * document stored inside @frame. * * Returns: A new #TextDisplay widget */ TextDisplay * text_display_new (TextFrame *frame) { return g_object_new (TEXT_TYPE_DISPLAY, "frame", frame, NULL); } static void text_display_finalize (GObject *object) { TextDisplay *self = (TextDisplay *)object; G_OBJECT_CLASS (text_display_parent_class)->finalize (object); } static void text_display_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { TextDisplay *self = TEXT_DISPLAY (object); switch (prop_id) { case PROP_FRAME: g_value_set_object (value, self->frame); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void text_display_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TextDisplay *self = TEXT_DISPLAY (object); switch (prop_id) { case PROP_FRAME: g_clear_object (&self->layout_tree); self->frame = g_value_get_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void layout_snapshot_recursive (GtkWidget *widget, TextLayoutBox *layout_box, GtkSnapshot *snapshot, GdkRGBA *fg_color, int *delta_height) { int offset = 0; for (TextNode *node = text_node_get_first_child (TEXT_NODE (layout_box)); node != NULL; node = text_node_get_next (node)) { g_assert (TEXT_IS_LAYOUT_BOX (node)); int delta_height; layout_snapshot_recursive (widget, node, snapshot, fg_color, &delta_height); offset += delta_height; } PangoLayout *layout = text_layout_box_get_pango_layout (layout_box); const TextDimensions *bbox = text_layout_box_get_bbox (layout_box); if (layout) { gtk_snapshot_save (snapshot); gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, offset)); gtk_snapshot_append_layout (snapshot, layout, fg_color); gtk_snapshot_restore (snapshot); offset = bbox->height; } gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, bbox->height)); *delta_height = bbox->height; } static void text_display_snapshot (GtkWidget *widget, GtkSnapshot *snapshot) { g_return_if_fail (TEXT_IS_DISPLAY (widget)); TextDisplay *self = TEXT_DISPLAY (widget); if (!self->frame) return; if (!self->layout_tree) return; // TODO: Don't recreate this each time - do in size allocate instead? g_clear_object (&self->layout_tree); self->layout_tree = text_layout_build_layout_tree (self->layout, gtk_widget_get_pango_context (GTK_WIDGET (self)), self->frame, gtk_widget_get_width (GTK_WIDGET (self))); GdkRGBA fg_color; gtk_style_context_get_color (gtk_widget_get_style_context (widget), &fg_color); // Display the layout tree int delta_height; layout_snapshot_recursive (widget, self->layout_tree, snapshot, &fg_color, &delta_height); } static GtkSizeRequestMode text_display_get_request_mode (GtkWidget* widget) { return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; } static void text_display_measure (GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum, int *natural, int *minimum_baseline, int *natural_baseline) { if (orientation == GTK_ORIENTATION_VERTICAL) { TextDisplay *self = TEXT_DISPLAY (widget); PangoContext *context = gtk_widget_get_pango_context (widget); g_clear_object (&self->layout_tree); self->layout_tree = text_layout_build_layout_tree (self->layout, context, self->frame, for_size); *minimum = *natural = text_layout_box_get_bbox (self->layout_tree)->height; g_debug ("Height: %d\n", *minimum); } else if (orientation == GTK_ORIENTATION_HORIZONTAL) { GTK_WIDGET_CLASS (text_display_parent_class)->measure (widget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline); } } static void text_display_class_init (TextDisplayClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = text_display_finalize; object_class->get_property = text_display_get_property; object_class->set_property = text_display_set_property; properties [PROP_FRAME] = g_param_spec_object ("frame", "Frame", "Frame", TEXT_TYPE_FRAME, G_PARAM_READWRITE|G_PARAM_CONSTRUCT); g_object_class_install_properties (object_class, N_PROPS, properties); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); widget_class->snapshot = text_display_snapshot; widget_class->get_request_mode = text_display_get_request_mode; widget_class->measure = text_display_measure; } static void text_display_init (TextDisplay *self) { self->layout = text_layout_new (); } text-engine-0.1.1/src/ui/display.h000066400000000000000000000020531422012432200167520ustar00rootroot00000000000000/* display.h * * Copyright 2022 Matthew Jakeman * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see . * * SPDX-License-Identifier: LGPL-3.0-or-later */ #pragma once #include #include "../model/frame.h" G_BEGIN_DECLS #define TEXT_TYPE_DISPLAY (text_display_get_type()) G_DECLARE_FINAL_TYPE (TextDisplay, text_display, TEXT, DISPLAY, GtkWidget) TextDisplay *text_display_new (TextFrame *frame); G_END_DECLS text-engine-0.1.1/src/ui/meson.build000066400000000000000000000002131422012432200172720ustar00rootroot00000000000000text_engine_sources += files([ 'display.c', ]) ui_headers = [ 'display.h', ] install_headers(ui_headers, subdir : header_dir / 'ui') text-engine-0.1.1/test/000077500000000000000000000000001422012432200147075ustar00rootroot00000000000000text-engine-0.1.1/test/delta.c000066400000000000000000000021511422012432200161430ustar00rootroot00000000000000#include #include typedef struct { int a; } DeltaFixture; static void delta_fixture_set_up (DeltaFixture *fixture, gconstpointer user_data) { fixture->a = 4; } static void delta_fixture_tear_down (DeltaFixture *fixture, gconstpointer user_data) { fixture->a = 0; } static void test_delta_test1 (DeltaFixture *fixture, gconstpointer user_data) { g_assert_true (fixture->a == 4); } static void test_delta_test2 (DeltaFixture *fixture, gconstpointer user_data) { g_assert_true (fixture->a != 5); } int main (int argc, char *argv[]) { setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); // Define the tests. g_test_add ("/text-engine/delta/test1", DeltaFixture, "some-user-data", delta_fixture_set_up, test_delta_test1, delta_fixture_tear_down); g_test_add ("/text-engine/delta/test2", DeltaFixture, "some-user-data", delta_fixture_set_up, test_delta_test2, delta_fixture_tear_down); return g_test_run (); } text-engine-0.1.1/test/meson.build000066400000000000000000000004331422012432200170510ustar00rootroot00000000000000deps = [ dependency('glib-2.0'), text_engine_dep ] test( 'delta', executable('delta', 'delta.c', dependencies: deps), env: [ 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()), 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()), ], protocol: 'tap', )