Commit cb032bc1 authored by XueShuming's avatar XueShuming
Browse files

update for impl hisvg

parent e5fd1ffd
......@@ -23,6 +23,7 @@ hiacejs_test
hiacejs_run
node_test
*.pc
.build
#log
......@@ -33,4 +34,6 @@ log
css_select_test
css_select_test2
test/layout_test
tests/svg2png
tests/*.png
*.a
......@@ -2,10 +2,12 @@ cmake_minimum_required(VERSION 3.10)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
find_package(GLIB 2.0 REQUIRED)
find_package(GLIB 2.40.0 REQUIRED COMPONENTS gio gio-unix gobject gthread gmodule)
find_package(HiDomLayout REQUIRED)
find_package(Cairo REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(Pango REQUIRED)
add_subdirectory(src)
add_subdirectory(tests)
......@@ -15,7 +15,10 @@ echo ""
echo "ROOT_DIR=$ROOT_DIR"
echo ""
cmake -DCMAKE_INSTALL_PREFIX=$ROOT_DIR/usr
mkdir -p .build
cd .build
cmake -DCMAKE_INSTALL_PREFIX=$ROOT_DIR/usr ..
#make VERBOSE=1
make
cd ..
find_package(PkgConfig)
if(Pango_FIND_REQUIRED)
set(_pkgconfig_REQUIRED "REQUIRED")
else(Pango_FIND_REQUIRED)
set(_pkgconfig_REQUIRED "")
endif(Pango_FIND_REQUIRED)
if(PANGO_MIN_VERSION)
pkg_check_modules(PANGO ${_pkgconfig_REQUIRED} "pango>=${PANGO_MIN_VERSION}" "pangocairo>=${PANGO_MIN_VERSION}")
else(PANGO_MIN_VERSION)
pkg_check_modules(PANGO ${_pkgconfig_REQUIRED} pango pangocairo)
endif(PANGO_MIN_VERSION)
if(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND)
find_path(PANGO_INCLUDE_DIRS pango.h)
find_library(PANGO_LIBRARIES pango pangocairo)
else(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND)
set(PANGO_LIBS_ABSOLUTE)
foreach(lib ${PANGO_LIBRARIES})
set(var_name PANGO_${lib}_ABS)
find_library(${var_name} ${lib} ${PANGO_LIBRARY_DIRS})
list(APPEND PANGO_LIBS_ABSOLUTE ${${var_name}})
endforeach()
set(PANGO_LIBRARIES ${PANGO_LIBS_ABSOLUTE})
endif(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PANGO DEFAULT_MSG PANGO_LIBRARIES PANGO_INCLUDE_DIRS)
mark_as_advanced(PANGO_LIBRARIES PANGO_INCLUDE_DIRS)
#ifndef _HI_SVG_BASE_H_
#define _HI_SVG_BASE_H_
#include "hisvg.h"
#include <libxml/SAX.h>
typedef struct HiSVGDpi_ {
double x;
double y;
} HiSVGDpi;
typedef struct HiSVGLoadFlags_ {
uint8_t unlimited_size;
uint8_t keep_image_data;
} HiSVGLoadFlags;
typedef struct HiSVGHandle_ {
HiSVGDpi dpi;
HiSVGLoadFlags load_flags;
char* base_url;
uint8_t is_testing;
xmlParserCtxtPtr ctxt;
GError** error;
gboolean is_closed;
gboolean finished;
} HiSVGHandle;
#ifdef __cplusplus
extern "C" {
#endif
void _hisvg_set_load_flags(HiSVGLoadFlags* load_flags, HiSVGHandleFlags flags);
HiSVGHandleFlags _hisvg_get_load_flags(HiSVGLoadFlags* load_flags);
void _hisvg_set_testing(HiSVGHandle* handle, uint8_t testing);
uint8_t _hisvg_get_testing(HiSVGHandle* handle);
void _hisvg_return_if_fail_warning (const char *pretty_function,
const char *expression, GError ** error);
void _hisvg_set_error (GError** error, xmlParserCtxtPtr ctxt);
gboolean _hisvg_handle_write (HiSVGHandle* handle, const guchar* buf,
gsize count, GError** error);
gboolean _hisvg_handle_close (HiSVGHandle* handle, GError** error);
gboolean _hisvg_handle_fill_with_data (HiSVGHandle* handle, const char* data,
gsize data_len, GError ** error);
#ifdef __cplusplus
}
#endif
#define _hisvg_return_if_fail(expr, error) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
_hisvg_return_if_fail_warning (G_STRFUNC, \
#expr, error); \
return; \
}; }G_STMT_END
#define _hisvg_return_val_if_fail(expr,val,error) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
_hisvg_return_if_fail_warning (G_STRFUNC, \
#expr, error); \
return (val); \
}; }G_STMT_END
#endif // _HI_SVG_BASE_H_
/////////////////////////////////////////////////////////////////////////////// //
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
\verbatim
This file is part of hiSVG. hiSVG is a high performance SVG
rendering library.
Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Or,
As this program is a library, any link to this program must follow
GNU General Public License version 3 (GPLv3). If you cannot accept
GPLv3, you need to be licensed from FMSoft.
If you have got a commercial license of this program, please use it
under the terms and conditions of the commercial license.
For more information about the commercial license, please refer to
<http://www.minigui.com/blog/minigui-licensing-policy/>.
\endverbatim
*/
#ifndef HISVG_CAIRO_CLIP_H
#define HISVG_CAIRO_CLIP_H
#include "hisvg-mask.h"
#include "hisvg-cairo-render.h"
#include <cairo.h>
G_BEGIN_DECLS
G_GNUC_INTERNAL
void hisvg_cairo_clip (HiSVGDrawingCtx * ctx, HiSVGClipPath * clip, HiSVGBbox * bbox);
G_END_DECLS
#endif
/////////////////////////////////////////////////////////////////////////////// //
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
\verbatim
This file is part of hiSVG. hiSVG is a high performance SVG
rendering library.
Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Or,
As this program is a library, any link to this program must follow
GNU General Public License version 3 (GPLv3). If you cannot accept
GPLv3, you need to be licensed from FMSoft.
If you have got a commercial license of this program, please use it
under the terms and conditions of the commercial license.
For more information about the commercial license, please refer to
<http://www.minigui.com/blog/minigui-licensing-policy/>.
\endverbatim
*/
#ifndef HISVG_CAIRO_DRAW_H
#define HISVG_CAIRO_DRAW_H
#include "hisvg-private.h"
G_BEGIN_DECLS
G_GNUC_INTERNAL
PangoContext *hisvg_cairo_create_pango_context (HiSVGDrawingCtx *ctx);
G_GNUC_INTERNAL
void hisvg_cairo_render_pango_layout (HiSVGDrawingCtx *ctx, PangoLayout *layout,
double x, double y);
G_GNUC_INTERNAL
void hisvg_cairo_render_path (HiSVGDrawingCtx *ctx,
const cairo_path_t *path);
G_GNUC_INTERNAL
void hisvg_cairo_render_surface (HiSVGDrawingCtx *ctx, cairo_surface_t *surface,
double x, double y, double w, double h);
G_GNUC_INTERNAL
void hisvg_cairo_push_discrete_layer (HiSVGDrawingCtx *ctx);
G_GNUC_INTERNAL
void hisvg_cairo_pop_discrete_layer (HiSVGDrawingCtx *ctx);
G_GNUC_INTERNAL
void hisvg_cairo_add_clipping_rect (HiSVGDrawingCtx *ctx,
double x, double y, double width, double height);
G_GNUC_INTERNAL
cairo_surface_t*hisvg_cairo_get_surface_of_node (HiSVGDrawingCtx *ctx, HiSVGNode *drawable,
double width, double height);
G_END_DECLS
#endif /*HISVG_CAIRO_DRAW_H */
/////////////////////////////////////////////////////////////////////////////// //
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
\verbatim
This file is part of hiSVG. hiSVG is a high performance SVG
rendering library.
Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Or,
As this program is a library, any link to this program must follow
GNU General Public License version 3 (GPLv3). If you cannot accept
GPLv3, you need to be licensed from FMSoft.
If you have got a commercial license of this program, please use it
under the terms and conditions of the commercial license.
For more information about the commercial license, please refer to
<http://www.minigui.com/blog/minigui-licensing-policy/>.
\endverbatim
*/
#ifndef HISVG_CAIRO_RENDER_H
#define HISVG_CAIRO_RENDER_H
#include "hisvg-private.h"
#include <cairo.h>
G_BEGIN_DECLS typedef struct _HiSVGCairoRender HiSVGCairoRender;
struct _HiSVGCairoRender {
HiSVGRender super;
cairo_t *cr;
double width;
double height;
cairo_t *initial_cr;
double offset_x;
double offset_y;
GList *cr_stack;
HiSVGBbox bbox;
GList *bb_stack;
GList *surfaces_stack;
};
#define HISVG_CAIRO_RENDER(render) (_HISVG_RENDER_CIC ((render), HISVG_RENDER_TYPE_CAIRO, HiSVGCairoRender))
G_GNUC_INTERNAL
HiSVGCairoRender *hisvg_cairo_render_new (cairo_t * cr, double width, double height);
G_GNUC_INTERNAL
void hisvg_cairo_render_hisvg_handle (cairo_t * cr, HiSVGHandle * handle);
G_GNUC_INTERNAL
HiSVGDrawingCtx *hisvg_cairo_new_drawing_ctx (cairo_t * cr, HiSVGHandle * handle);
HiSVGDrawingCtx *hisvg_cairo_new_drawing_ctx_with_viewport (cairo_t * cr, HiSVGHandle * handle, const HiSVGRect* viewport);
G_END_DECLS
#endif
/////////////////////////////////////////////////////////////////////////////// //
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
\verbatim
This file is part of hiSVG. hiSVG is a high performance SVG
rendering library.
Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Or,
As this program is a library, any link to this program must follow
GNU General Public License version 3 (GPLv3). If you cannot accept
GPLv3, you need to be licensed from FMSoft.
If you have got a commercial license of this program, please use it
under the terms and conditions of the commercial license.
For more information about the commercial license, please refer to
<http://www.minigui.com/blog/minigui-licensing-policy/>.
\endverbatim
*/
#ifndef HISVG_H
#define HISVG_H
#define __HISVG_HISVG_H_INSIDE__
#include <glib-object.h>
#include <gio/gio.h>
#include "hisvg.h"
G_BEGIN_DECLS
#if defined(HISVG_DISABLE_DEPRECATION_WARNINGS) || !GLIB_CHECK_VERSION (2, 31, 0)
#define HISVG_DEPRECATED
#define HISVG_DEPRECATED_FOR(f)
#else
#define HISVG_DEPRECATED G_DEPRECATED
#define HISVG_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f)
#endif
#define HISVG_TYPE_HANDLE (hisvg_handle_get_type ())
#define HISVG_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HISVG_TYPE_HANDLE, HiSVGHandle))
#define HISVG_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HISVG_TYPE_HANDLE, HiSVGHandleClass))
#define HISVG_IS_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HISVG_TYPE_HANDLE))
#define HISVG_IS_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HISVG_TYPE_HANDLE))
#define HISVG_HANDLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HISVG_TYPE_HANDLE, HiSVGHandleClass))
GType hisvg_handle_get_type (void);
/**
* HiSVGError:
* @HISVG_ERROR_FAILED: the request failed
*
* An enumeration representing possible errors
*/
typedef enum {
HISVG_ERROR_FAILED
} HiSVGError;
/**
* HiSVGHandle:
*
* The #HiSVGHandle is an object representing the parsed form of a SVG
*/
typedef struct _HiSVGHandle HiSVGHandle;
typedef struct HiSVGHandlePrivate HiSVGHandlePrivate;
typedef struct _HiSVGHandleClass HiSVGHandleClass;
typedef struct _HiSVGDimensionData HiSVGDimensionData;
typedef struct _HiSVGPositionData HiSVGPositionData;
/**
* HiSVGHandleClass:
* @parent: parent class
*
* Class structure for #HiSVGHandle
*/
struct _HiSVGHandleClass {
GObjectClass parent;
/*< private >*/
gpointer _abi_padding[15];
};
struct _HiSVGHandle {
GObject parent;
/*< private >*/
HiSVGHandlePrivate *priv;
gpointer _abi_padding[15];
};
/**
* HiSVGDimensionData:
* @width: SVG's width, in pixels
* @height: SVG's height, in pixels
* @em: em
* @ex: ex
*/
struct _HiSVGDimensionData {
int width;
int height;
gdouble em;
gdouble ex;
};
/**
* HiSVGPositionData:
* @x: position on the x axis
* @y: position on the y axis
*
* Position of an SVG fragment.
*/
struct _HiSVGPositionData {
int x;
int y;
};
void hisvg_cleanup (void);
gboolean hisvg_handle_write (HiSVGHandle * handle, const guchar * buf,
gsize count, GError ** error);
gboolean hisvg_handle_close (HiSVGHandle * handle, GError ** error);
void hisvg_handle_get_dimensions_x (HiSVGHandle * handle, HiSVGDimensionData * dimension_data);
gboolean hisvg_handle_get_dimensions_sub (HiSVGHandle * handle, HiSVGDimensionData * dimension_data, const char *id);
gboolean hisvg_handle_get_position_sub (HiSVGHandle * handle, HiSVGPositionData * position_data, const char *id);
void hisvg_handle_set_base_gfile (HiSVGHandle *handle,
GFile *base_file);
gboolean hisvg_handle_read_stream_sync (HiSVGHandle *handle,
GInputStream *stream,
GCancellable *cancellable,
GError **error);
HiSVGHandle *hisvg_handle_new_from_gfile_sync (GFile *file,
HiSVGHandleFlags flags,
GCancellable *cancellable,
GError **error);
HiSVGHandle *hisvg_handle_new_from_stream_sync (GInputStream *input_stream,
GFile *base_file,
HiSVGHandleFlags flags,
GCancellable *cancellable,
GError **error);
G_END_DECLS
//#include "hisvg-enum-types.h"
#undef __HISVG_HISVG_H_INSIDE__
#endif /* HISVG_H */
/////////////////////////////////////////////////////////////////////////////// //
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/**
\verbatim
This file is part of hiSVG. hiSVG is a high performance SVG
rendering library.
Copyright (C) 2021 Beijing FMSoft Technologies Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Or,
As this program is a library, any link to this program must follow
GNU General Public License version 3 (GPLv3). If you cannot accept
GPLv3, you need to be licensed from FMSoft.
If you have got a commercial license of this program, please use it
under the terms and conditions of the commercial license.
For more information about the commercial license, please refer to
<http://www.minigui.com/blog/minigui-licensing-policy/>.
\endverbatim
*/
#ifndef HISVG_CSS_H
#define HISVG_CSS_H
#include <glib.h>
#ifdef HISVG_COMPILATION
#include <pango/pango.h>
#include "hisvg-private.h"
#endif
G_BEGIN_DECLS
#define HISVG_ASPECT_RATIO_NONE (0)
#define HISVG_ASPECT_RATIO_XMIN_YMIN (1 << 0)
#define HISVG_ASPECT_RATIO_XMID_YMIN (1 << 1)
#define HISVG_ASPECT_RATIO_XMAX_YMIN (1 << 2)
#define HISVG_ASPECT_RATIO_XMIN_YMID (1 << 3)
#define HISVG_ASPECT_RATIO_XMID_YMID (1 << 4)
#define HISVG_ASPECT_RATIO_XMAX_YMID (1 << 5)
#define HISVG_ASPECT_RATIO_XMIN_YMAX (1 << 6)
#define HISVG_ASPECT_RATIO_XMID_YMAX (1 << 7)
#define HISVG_ASPECT_RATIO_XMAX_YMAX (1 << 8)
#define HISVG_ASPECT_RATIO_SLICE (1 << 31)
/* This one is semi-public for mis-use in hisvg-convert */
guint32 hisvg_css_parse_color (const char *str, gboolean * inherit);
#ifdef HISVG_COMPILATION