freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2019-moazin 0ebc005 07/47: Barebones of an SVG renderin


From: Moazin Khatti
Subject: [freetype2] GSoC-2019-moazin 0ebc005 07/47: Barebones of an SVG rendering module and making it part of the build system
Date: Fri, 26 Jul 2019 10:01:56 -0400 (EDT)

branch: GSoC-2019-moazin
commit 0ebc005897e7b69e4acd7f5b5399d59f89d62b98
Author: Moazin Khatti <address@hidden>
Commit: Moazin Khatti <address@hidden>

    Barebones of an SVG rendering module and making it part of the build system
---
 include/freetype/config/ftmodule.h |  3 +-
 modules.cfg                        |  3 ++
 src/base/ftobjs.c                  |  3 ++
 src/svg/ftsvg.c                    | 79 ++++++++++++++++++++++++++++++++++++++
 src/svg/ftsvg.h                    | 32 +++++++++++++++
 src/svg/module.mk                  | 23 +++++++++++
 src/svg/rules.mk                   | 72 ++++++++++++++++++++++++++++++++++
 src/svg/svg.c                      | 25 ++++++++++++
 src/svg/svgtypes.c                 | 43 +++++++++++++++++++++
 9 files changed, 282 insertions(+), 1 deletion(-)

diff --git a/include/freetype/config/ftmodule.h 
b/include/freetype/config/ftmodule.h
index 7c603e5..0f37d07 100644
--- a/include/freetype/config/ftmodule.h
+++ b/include/freetype/config/ftmodule.h
@@ -22,7 +22,8 @@ FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class )
 FT_USE_MODULE( FT_Module_Class, psaux_module_class )
 FT_USE_MODULE( FT_Module_Class, psnames_module_class )
 FT_USE_MODULE( FT_Module_Class, pshinter_module_class )
-FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class )
+FT_USE_MODULE( FT_Renderer_Class, ft_svg_renderer_class )
+/*FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class )*/
 FT_USE_MODULE( FT_Module_Class, sfnt_module_class )
 FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class )
 FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class )
diff --git a/modules.cfg b/modules.cfg
index dc6c8d4..14ac1e5 100644
--- a/modules.cfg
+++ b/modules.cfg
@@ -99,6 +99,9 @@ RASTER_MODULES += raster
 # Anti-aliasing rasterizer.
 RASTER_MODULES += smooth
 
+# OT-SVG
+RASTER_MODULES += svg
+
 
 ####
 #### auxiliary modules
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index e301f8f..697066b 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -4538,7 +4538,10 @@
     {
     case FT_GLYPH_FORMAT_BITMAP:   /* already a bitmap, don't do anything */
       break;
+    case FT_GLYPH_FORMAT_SVG:      /* handle svg rendering */
+      renderer = FT_Lookup_Renderer( library, slot->format, NULL );
 
+      break;
     default:
       if ( slot->internal->load_flags & FT_LOAD_COLOR )
       {
diff --git a/src/svg/ftsvg.c b/src/svg/ftsvg.c
new file mode 100644
index 0000000..2f1570a
--- /dev/null
+++ b/src/svg/ftsvg.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ *
+ * ftsvg.c
+ *
+ *   The FreeType svg renderer interface (body).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT.  By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+#include <ft2build.h>
+#include <stdio.h>
+
+#include "ftsvg.h"
+
+  /* tmp hook injection */
+  FT_Error 
+  tmp_svg_lib_init()
+  {
+    FT_Error error = FT_Err_Ok;
+    printf("Init svg\n");
+    return error;
+  }
+
+  /* ft_svg_init */
+  static FT_Error
+  ft_svg_init( SVG_Renderer svg_module )
+  {
+    FT_Error           error = FT_Err_Ok;
+    SVG_RendererHooks  hooks;
+
+    hooks.svg_lib_init = tmp_svg_lib_init;
+    svg_module->hooks  = hooks;
+    svg_module->loaded = FALSE;
+
+    return error; 
+  }
+
+  static FT_Error
+  ft_svg_render( FT_Renderer       renderer,
+                 FT_GlyphSlot      slot,
+                 FT_Render_Mode    mode,
+                 const FT_Vector*  origin )
+  {
+    SVG_Renderer renderer_ = (SVG_Renderer)renderer;
+    if( renderer_->loaded == FALSE )
+      renderer_->loaded = TRUE;
+    renderer_->hooks.svg_lib_init();
+  }
+
+
+
+  FT_DEFINE_RENDERER(
+    ft_svg_renderer_class,
+
+      FT_MODULE_RENDERER,
+      sizeof( SVG_RendererRec ),
+
+      "ot-svg",
+      0x10000L,
+      0x20000L,
+      NULL,     /* module specific interface */
+      (FT_Module_Constructor)ft_svg_init,     /* module_init */
+      NULL,
+      NULL,
+      FT_GLYPH_FORMAT_SVG,
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      NULL
+  )
diff --git a/src/svg/ftsvg.h b/src/svg/ftsvg.h
new file mode 100644
index 0000000..3c99677
--- /dev/null
+++ b/src/svg/ftsvg.h
@@ -0,0 +1,32 @@
+/****************************************************************************
+ *
+ * ftsvg.h
+ *
+ *   The FreeType svg renderer interface (specification).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT.  By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+#ifndef FTSVG_H_
+#define FTSVG_H_
+
+#include <ft2build.h>
+#include FT_RENDER_H
+
+FT_BEGIN_HEADER
+
+    FT_DECLARE_RENDERER( ft_svg_renderer_class )
+
+FT_END_HEADER
+
+#endif /* FTSVG_H_ */
+
+/* END */
diff --git a/src/svg/module.mk b/src/svg/module.mk
new file mode 100644
index 0000000..b6efa17
--- /dev/null
+++ b/src/svg/module.mk
@@ -0,0 +1,23 @@
+#
+# FreeType 2 svg renderer module definition
+#
+
+
+# Copyright (C) 1996-2019 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
+
+
+FTMODULE_H_COMMANDS += SVG_MODULE
+
+define SVG_MODULE
+$(OPEN_DRIVER) FT_Renderer_Class, ft_svg_renderer_class $(CLOSE_DRIVER)
+$(ECHO_DRIVER)svg    $(ECHO_DRIVER_DESC)svg renderer module$(ECHO_DRIVER_DONE)
+endef
+
+# EOF
diff --git a/src/svg/rules.mk b/src/svg/rules.mk
new file mode 100644
index 0000000..0f14de4
--- /dev/null
+++ b/src/svg/rules.mk
@@ -0,0 +1,72 @@
+#
+# FreeType 2 svg renderer module build rules
+#
+
+
+# Copyright (C) 1996-2019 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
+
+
+# svg renderer driver directory
+#
+SVG_DIR := $(SRC_DIR)/svg
+
+# compilation flags for the driver
+#
+SVG_COMPILE := $(CC) $(ANSIFLAGS)                               \
+                        $I$(subst /,$(COMPILER_SEP),$(SVG_DIR)) \
+                        $(INCLUDE_FLAGS)                           \
+                        $(FT_CFLAGS)
+
+
+# raster driver sources (i.e., C files)
+#
+SVG_DRV_SRC := $(SVG_DIR)/ftsvg.c \
+              $(SVG_DIR)/svgtypes.c
+
+
+# raster driver headers
+#
+SVG_DRV_H := $(SVG_DIR)/ftsvg.h
+
+
+# raster driver object(s)
+#
+#   RASTER_DRV_OBJ_M is used during `multi' builds.
+#   RASTER_DRV_OBJ_S is used during `single' builds.
+#
+#RASTER_DRV_OBJ_M := $(RASTER_DRV_SRC:$(RASTER_DIR)/%.c=$(OBJ_DIR)/%.$O)
+SVG_DRV_OBJ_M := $(SVG_DRV_SRC:$(SVG_DIR)/%.c=$(OBJ_DIR)/%.$O)
+SVG_DRV_OBJ_S := $(OBJ_DIR)/svg.$O
+
+# raster driver source file for single build
+#
+SVG_DRV_SRC_S := $(SVG_DIR)/svg.c
+
+
+# raster driver - single object
+#
+$(SVG_DRV_OBJ_S): $(SVG_DRV_SRC_S) $(SVG_DRV_SRC) \
+                     $(FREETYPE_H) $(SVG_DRV_H)
+       $(SVG_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(SVG_DRV_SRC_S))
+
+
+# raster driver - multiple objects
+#
+$(OBJ_DIR)/%.$O: $(SVG_DIR)/%.c $(FREETYPE_H) $(SVG_DRV_H)
+       $(SVG_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
+
+
+# update main driver object lists
+#
+DRV_OBJS_S += $(SVG_DRV_OBJ_S)
+DRV_OBJS_M += $(SVG_DRV_OBJ_M)
+
+
+# EOF
diff --git a/src/svg/svg.c b/src/svg/svg.c
new file mode 100644
index 0000000..660bb1c
--- /dev/null
+++ b/src/svg/svg.c
@@ -0,0 +1,25 @@
+/****************************************************************************
+ *
+ * svg.c
+ *
+ *   FreeType svg renderer module component (body only).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT.  By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+#define FT_MAKE_OPTION_SINGLE_OBJECT
+#include <ft2build.h>
+
+#include "svgtypes.c"
+#include "ftsvg.c"
+
+
+/* END */
diff --git a/src/svg/svgtypes.c b/src/svg/svgtypes.c
new file mode 100644
index 0000000..f3f7010
--- /dev/null
+++ b/src/svg/svgtypes.c
@@ -0,0 +1,43 @@
+/****************************************************************************
+ *
+ * svgtypes.h
+ *
+ *   TODO:
+ *   The FreeType svg renderer internal types (specification).
+ *
+ * Copyright (C) 1996-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT.  By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+#include <ft2build.h>
+#include FT_INTERNAL_OBJECTS_H
+#include FT_RENDER_H
+
+
+  /* Function Pointer definitions for SVG_RendererHooks */
+  typedef FT_Error (*SVG_Lib_Init)(); /* initialize the external lib */
+  typedef FT_Error (*SVG_Lib_Free)(); /* destroy the external lib */
+
+  typedef struct SVG_RendererHooks_
+  {
+    /* Api Hooks for OT-SVG Rendering */ 
+    SVG_Lib_Init  svg_lib_init;
+    SVG_Lib_Free  svg_lib_free;
+  } SVG_RendererHooks;
+
+  typedef struct SVG_RendererRec_
+  {
+    FT_RendererRec     root;   /* This inherits FT_RendererRec */
+    FT_Bool            loaded;
+    SVG_RendererHooks  hooks;  /* Holds out hooks to the outside library */
+  } SVG_RendererRec;
+
+  typedef struct SVG_RendererRec_*  SVG_Renderer;
+



reply via email to

[Prev in Thread] Current Thread [Next in Thread]