Skip to content

Commit

Permalink
[66_2] L3: Add Graphics/Renderer, Graphics/Pictures, Plugins/Freetype…
Browse files Browse the repository at this point in the history
…, Plugins/Metafont, Plugins/Xml
  • Loading branch information
da-liii authored Nov 29, 2023
1 parent dd5858a commit 36b9f90
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 66 deletions.
59 changes: 59 additions & 0 deletions src/Data/Tree/tree_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/

#include "tree_helper.hpp"
#include "analyze.hpp"
#include "modification.hpp"

tree_label
Expand Down Expand Up @@ -293,3 +294,61 @@ print_tree (tree t, int tab) {
print_tree (t[i], tab + 2);
}
}

/******************************************************************************
* Percentages and magnifications
******************************************************************************/

bool
is_percentage (tree t, string s) {
return is_atomic (t) && ends (t->label, s) &&
is_double (t->label (0, N (t->label) - 1));
}

bool
is_percentage (tree t) {
return is_percentage (t, "%");
}

double
as_percentage (tree t) {
return as_double (t->label (0, N (t->label) - 1)) / 100.0;
}

bool
is_magnification (string s) {
double result;
if (N (s) == 0) return false;
for (int i= 0; i < N (s); /*nop*/) {
if (s[i] == '*') {
i++;
read_double (s, i, result);
}
else if (s[i] == '/') {
i++;
read_double (s, i, result);
}
else return false;
}
return true;
}

double
get_magnification (string s) {
int i = 0;
double magn= 1.0, result;
while (i < N (s)) {
if (s[i] == '*') {
i++;
read_double (s, i, result);
magn*= result;
}
else if (s[i] == '/') {
i++;
read_double (s, i, result);
magn/= result;
}
else return magn;
}
return magn;
}
6 changes: 6 additions & 0 deletions src/Data/Tree/tree_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,10 @@ verbatim (tree t1) {
string tree_as_string (tree t);
void print_tree (tree t, int tab= 0);

bool is_percentage (tree t, string s);
bool is_percentage (tree t);
double as_percentage (tree t);
bool is_magnification (string s);
double get_magnification (string s);

#endif
2 changes: 1 addition & 1 deletion src/Graphics/Pictures/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "effect.hpp"
#include "true_color.hpp"
#include "gui.hpp"
#include "colors.hpp"
#include "matrix.hpp"

/******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Pictures/picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

#include "renderer.hpp"
#include "analyze.hpp"
#include "gui.hpp"
#include "image_files.hpp"
#include "true_color.hpp"
#include "colors.hpp"
#include "iterator.hpp"
#include "file.hpp"
#include "tm_file.hpp"
#include "effect.hpp"
#include "tm_timer.hpp"

/******************************************************************************
* Unique id for pictures
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Pictures/raster_picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
******************************************************************************/

#include "raster_picture.hpp"
#include "gui.hpp"
#include "colors.hpp"

/******************************************************************************
* Constructor
Expand Down
11 changes: 8 additions & 3 deletions src/Graphics/Renderer/brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
******************************************************************************/

#include "renderer.hpp"
#include "gui.hpp"
#include "image_files.hpp"
#include "true_color.hpp"
#include "tm_url.hpp"
#include "colors.hpp"
#include "tree_analyze.hpp"

#if not defined(KERNEL_L3)
url get_current_buffer_safe ();
bool is_percentage (tree t, string s= "%");
double as_percentage (tree t);
#endif

/******************************************************************************
* Equality
Expand Down Expand Up @@ -111,7 +112,11 @@ brush_rep::get_pattern_url () {
url u= url_system (as_string (t[0]));
url r= resolve_pattern (u);
if (!is_none (r)) return r;
#if defined(KERNEL_L3)
url base= url_pwd ();
#else
url base= get_current_buffer_safe ();
#endif
r= resolve (relative (base, u));
if (!is_none (r)) return r;
return u;
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Renderer/pencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
******************************************************************************/

#include "pencil.hpp"
#include "gui.hpp"
#include "url.hpp"
#include "colors.hpp"

/******************************************************************************
* Invisible pencils
Expand Down
1 change: 1 addition & 0 deletions src/Graphics/Renderer/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "link.hpp"
#include "frame.hpp"
#include "converter.hpp"
#include "colors.hpp"

#ifdef USE_PLUGIN_PDF
#include "Pdf/pdf_hummus_renderer.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/Graphics/Renderer/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#ifndef PRINTER_H
#define PRINTER_H
#include "renderer.hpp"
#include "gui.hpp"
#include "hashmap.hpp"
#include "url.hpp"

Expand Down
6 changes: 2 additions & 4 deletions src/Graphics/Renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
******************************************************************************/

#include "renderer.hpp"
#include "gui.hpp"
#include "rectangles.hpp"
#include "image_files.hpp"
#include "frame.hpp"
#include "colors.hpp"
#include "tree_analyze.hpp"

int std_shrinkf = 5;
#ifdef OS_WASM
Expand Down Expand Up @@ -349,9 +350,6 @@ renderer_rep::get_brush () {
return brush (get_pencil () -> get_brush ());
}

bool is_percentage (tree t, string s= "%");
double as_percentage (tree t);

void
renderer_rep::clear_pattern (SI mx1, SI my1, SI mx2, SI my2,
SI x1, SI y1, SI x2, SI y2) {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Freetype/free_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

#include "config.h"
#include "free_type.hpp"
#include "dyn_link.hpp"
#include "tm_debug.hpp"

#ifdef USE_FREETYPE
#include "dyn_link.hpp"

static bool ft_initialized= false;
static bool ft_error = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Plugins/Metafont/tex_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "Metafont/load_tex.hpp"
#include "translator.hpp"
#include "iterator.hpp"
#include "gui.hpp"
#include "analyze.hpp"
#include "colors.hpp"

#define TEX_ANY 0
#define TEX_EC 1
Expand Down
5 changes: 4 additions & 1 deletion src/System/config_l3.h.xmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
${define HAVE_INTPTR_T}
${define HAVE_STDINT_H}
${define QTTEXMACS}
${define SANITY_CHECKS}
${define SANITY_CHECKS}

/* Use freetype library */
${define USE_FREETYPE}
46 changes: 0 additions & 46 deletions src/Typeset/Env/env_length.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,52 +309,6 @@ edit_env_rep::as_point (tree t) {
return point ();
}

/******************************************************************************
* Percentages and magnifications
******************************************************************************/

bool
is_percentage (tree t, string s) {
return
is_atomic (t) &&
ends (t->label, s) &&
is_double (t->label (0, N (t->label) - 1));
}

bool
is_percentage (tree t) {
return is_percentage (t, "%");
}

double
as_percentage (tree t) {
return as_double (t->label (0, N (t->label) - 1)) / 100.0;
}

bool
is_magnification (string s) {
double result;
if (N(s) == 0) return false;
for (int i=0; i<N(s); /*nop*/) {
if (s[i]=='*') { i++; read_double (s, i, result); }
else if (s[i]=='/') { i++; read_double (s, i, result); }
else return false;
}
return true;
}

double
get_magnification (string s) {
int i=0;
double magn= 1.0, result;
while (i<N(s)) {
if (s[i]=='*') { i++; read_double (s, i, result); magn *= result; }
else if (s[i]=='/') { i++; read_double (s, i, result); magn /= result; }
else return magn;
}
return magn;
}

/******************************************************************************
* Built-in length units
******************************************************************************/
Expand Down
5 changes: 0 additions & 5 deletions src/Typeset/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,6 @@ tm_ostream& operator << (tm_ostream& out, edit_env env);
tree texmacs_exec (edit_env env, tree cmd);
tree load_inclusion (url u); // implemented in tm_file.cpp
tree tree_extents (tree t);
bool is_percentage (tree t, string s);
bool is_percentage (tree t);
double as_percentage (tree t);
bool is_magnification (string s);
double get_magnification (string s);
int decode_alpha (string s);
array<double> get_control_times (tree t);

Expand Down
30 changes: 30 additions & 0 deletions tests/L3/Graphics/Fonts/font_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

/*****************************************************************************
* MODULE : font_test.cpp
* DESCRIPTION: Tests on font
* COPYRIGHT : (C) 2023 Darcy Shen
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#include "font.hpp"
#include <QtTest/QtTest>

class TestFont : public QObject {
Q_OBJECT

private slots:
void test_get_extents ();
};

void
TestFont::test_get_extents () {
// sys-chinese-rm-medium-right-10-600-smart
// font fn= smart_font ("sys-chinese", "rm", "medium", "right", 10, 600);
// cout << fn->res_name << LF;
}

QTEST_MAIN (TestFont)
#include "font_test.moc"
1 change: 1 addition & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ target("libkernel_l3") do
filename = "L3/config.h",
variables = {
QTTEXMACS = false,
USE_FREETYPE = true,
}
})
add_configfiles("src/System/tm_configure_l3.hpp.xmake", {
Expand Down
12 changes: 12 additions & 0 deletions xmake/L3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local l3_files = {
"$(projectdir)/src/Data/Observers/**.cpp",
"$(projectdir)/src/Data/Scheme/**.cpp",
"$(projectdir)/src/Data/String/**.cpp",
"$(projectdir)/src/Data/Convert/Generic/**.cpp",
"$(projectdir)/src/Data/Document/new_document.cpp",
"$(projectdir)/src/Data/Drd/**.cpp",
"$(projectdir)/src/Data/Tree/tree_helper.cpp",
Expand All @@ -24,6 +25,8 @@ local l3_files = {
"$(projectdir)/src/Graphics/Types/**.cpp",
"$(projectdir)/src/Graphics/Fonts/**.cpp",
"$(projectdir)/src/Graphics/Bitmap_fonts/**.cpp",
"$(projectdir)/src/Graphics/Renderer/**.cpp",
"$(projectdir)/src/Graphics/Pictures/**.cpp",
"$(projectdir)/src/Scheme/L1/**.cpp",
"$(projectdir)/src/Scheme/L2/**.cpp",
"$(projectdir)/src/Scheme/L3/**.cpp",
Expand All @@ -32,10 +35,16 @@ local l3_files = {
"$(projectdir)/src/System/Config/**.cpp",
"$(projectdir)/src/System/Classes/**.cpp",
"$(projectdir)/src/System/Files/**files.cpp",
"$(projectdir)/src/System/Files/tm_file.cpp",
"$(projectdir)/src/System/Link/tm_link.cpp",
"$(projectdir)/src/System/Link/dyn_link.cpp",
"$(projectdir)/src/System/Misc/data_cache.cpp",
"$(projectdir)/src/System/Misc/persistent.cpp",
"$(projectdir)/src/System/Misc/tm_sys_utils.cpp",
"$(projectdir)/src/Texmacs/Server/tm_debug.cpp",
"$(projectdir)/src/Plugins/Metafont/**.cpp",
"$(projectdir)/src/Plugins/Freetype/**.cpp",
"$(projectdir)/src/Plugins/Xml/**.cpp"
}
local l3_includedirs = {
"src/Kernel/Types",
Expand Down Expand Up @@ -64,11 +73,13 @@ local l3_includedirs = {
"src/Scheme/L3",
"src/System/Config",
"src/System/Language",
"src/System/Link",
"src/System/Files",
"src/System/Classes",
"src/System/Misc",
"src/Plugins",
"src/Texmacs",
"TeXmacs/include",
}

function add_target_L3()
Expand All @@ -82,6 +93,7 @@ function add_target_L3()

add_packages("s7")
add_packages("lolly")
add_packages("freetype")

add_includedirs("$(buildir)/L3")
add_includedirs("$(buildir)/glue")
Expand Down

0 comments on commit 36b9f90

Please sign in to comment.