summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2022-01-06 18:24:02 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2022-01-06 18:24:02 +0100
commitca8010bf87a91fea71df17fe18cef3c8cb381087 (patch)
tree880a5873a0e2b39481c54e843839d6a08b0cda09
parent9f0b74c3fcaceeb42771be6b0956a74c8941f944 (diff)
vkvg-svg library integration
-rw-r--r--CMakeLists.txt39
-rw-r--r--Findvkvg.cmake15
-rw-r--r--cmake/GitSubmoduleUpdate.cmake12
m---------external/vkvg-svg0
-rw-r--r--include/vkvg-svg.h (renamed from include/vkvg-nsvg.h)52
-rw-r--r--src/nsvg/nanosvg.h (renamed from src/nanosvg.h)0
-rw-r--r--src/nsvg/vkvg_nsvg.c (renamed from src/vkvg_nsvg.c)0
-rw-r--r--src/vkvg_context.c32
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/svg.c19
10 files changed, 100 insertions, 70 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a00419b..ef9718a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,19 +84,7 @@ IF (VKVG_SVG)
ADD_DEFINITIONS (-DVKVG_SVG)
ENDIF ()
-
-FUNCTION (updateGitSubmodule SUBMOD_NAME)
- MESSAGE(STATUS "Git Submodule ${SUBMOD_NAME} update")
- EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${SUBMOD_NAME}
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- RESULT_VARIABLE GIT_SUBMOD_RESULT)
- if(NOT GIT_SUBMOD_RESULT EQUAL "0")
- message(FATAL_ERROR "git submodule update --init --recursive ${SUBMOD_NAME} failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
- endif()
-ENDFUNCTION (updateGitSubmodule)
-
-
-FIND_PACKAGE(Git QUIET)
+INCLUDE ("${CMAKE_CURRENT_SOURCE_DIR}/cmake/GitSubmoduleUpdate.cmake")
IF(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
OPTION(GIT_SUBMODULE "Check submodules during build" ON)
@@ -214,19 +202,25 @@ ENDIF()
IF (VKVG_FILL_NZ_GLUTESS)
ADD_SUBDIRECTORY (external/glutess)
ENDIF ()
-IF (VKVG_SVG AND NOT TARGET vkvk-svg)
- ADD_SUBDIRECTORY (external/vkvg-svg)
-ENDIF()
-
FILE(GLOB VKVG_SRC src/*.c)
-SET (VKVG_PUBLIC_HEADERS "include/vkvg.h;include/vkvg-nsvg.h")
+SET (VKVG_PUBLIC_HEADERS "include/vkvg.h")
+
+IF (NOT VKVG_SVG)
+ SET (VKVG_PUBLIC_HEADERS "${VKVG_PUBLIC_HEADERS};include/vkvg-svg.h")
+ FILE(GLOB NSVG_SRC src/nsvg/*.c)
+ LIST (APPEND VKVG_SRC ${NSVG_SRC})
+ENDIF()
CONFIGURE_FILE(vkvg.pc.in vkvg.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/vkvg.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
ADD_LIBRARY("${PROJECT_NAME}" ${VKVG_SRC} ${SHADERS} ${SHADERS_H} )
+IF (VKVG_SVG AND NOT TARGET vkvk-svg)
+ ADD_SUBDIRECTORY (external/vkvg-svg)
+ENDIF()
+
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}
VERSION ${vkvg_VERSION_MAJOR}.${vkvg_VERSION_MINOR}
@@ -239,14 +233,14 @@ TARGET_INCLUDE_DIRECTORIES("${PROJECT_NAME}"
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/vkh/src
- "$<$<BOOL:${VKVG_USE_FREETYPE}>:${FREETYPE_INCLUDE_DIRS}>"
- "$<$<BOOL:${VKVG_USE_HARFBUZZ}>:${HarfBuzz_INCLUDE_DIRS}>"
- "$<$<BOOL:${VKVG_USE_FONTCONFIG}>:${Fontconfig_INCLUDE_DIRS}>"
+ $<$<BOOL:${VKVG_USE_FREETYPE}>:${FREETYPE_INCLUDE_DIRS}>
+ $<$<BOOL:${VKVG_USE_HARFBUZZ}>:${HarfBuzz_INCLUDE_DIRS}>
+ $<$<BOOL:${VKVG_USE_FONTCONFIG}>:${Fontconfig_INCLUDE_DIRS}>
+ $<$<NOT:$<BOOL:${VKVG_SVG}>>:${CMAKE_CURRENT_SOURCE_DIR}/src/nsvg>
PUBLIC
${Vulkan_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/vkh/include
- "$<$<BOOL:${VKVG_SVG}>:${CMAKE_CURRENT_SOURCE_DIR}/external/vkvg-svg/include>"
)
TARGET_LINK_LIBRARIES("${PROJECT_NAME}"
PUBLIC
@@ -258,7 +252,6 @@ TARGET_LINK_LIBRARIES("${PROJECT_NAME}"
"$<$<BOOL:${VKVG_USE_HARFBUZZ}>:${HarfBuzz_LIBRARIES}>"
"$<$<BOOL:${VKVG_USE_FONTCONFIG}>:${Fontconfig_LIBRARIES}>"
"$<$<BOOL:${VKVG_FILL_NZ_GLUTESS}>:glutess>"
- "$<$<BOOL:${VKVG_SVG}>:vkvg-svg>"
)
INSTALL(TARGETS "${PROJECT_NAME}"
diff --git a/Findvkvg.cmake b/Findvkvg.cmake
new file mode 100644
index 0000000..a11a14d
--- /dev/null
+++ b/Findvkvg.cmake
@@ -0,0 +1,15 @@
+find_path(vkvg_INCLUDE_DIR vkvg.h)
+
+find_library(vkvg_LIBRARY NAMES vkvg)
+
+# handle the QUIETLY and REQUIRED arguments and set vkvg_FOUND to TRUE if
+# all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(vkvg DEFAULT_MSG
+ vkvg_LIBRARY vkvg_INCLUDE_DIR)
+
+if(vkvg_FOUND)
+ set( vkvg_LIBRARIES ${vkvg_LIBRARY} )
+endif()
+
+mark_as_advanced(vkvg_INCLUDE_DIR vkvg_LIBRARY vkvg_LIBRARIES)
diff --git a/cmake/GitSubmoduleUpdate.cmake b/cmake/GitSubmoduleUpdate.cmake
new file mode 100644
index 0000000..5c061f7
--- /dev/null
+++ b/cmake/GitSubmoduleUpdate.cmake
@@ -0,0 +1,12 @@
+FUNCTION (updateGitSubmodule SUBMOD_NAME)
+ MESSAGE(STATUS "Git Submodule ${SUBMOD_NAME} update")
+ EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${SUBMOD_NAME}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ RESULT_VARIABLE GIT_SUBMOD_RESULT)
+ if(NOT GIT_SUBMOD_RESULT EQUAL "0")
+ message(FATAL_ERROR "git submodule update --init --recursive ${SUBMOD_NAME} failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
+ endif()
+ENDFUNCTION (updateGitSubmodule)
+
+
+FIND_PACKAGE(Git QUIET)
diff --git a/external/vkvg-svg b/external/vkvg-svg
-Subproject 40415fe50e6f863b4abaac1b55c0504f48cf54b
+Subproject a663be0bd92d3e7c4f8425da250f8d8bd636f2f
diff --git a/include/vkvg-nsvg.h b/include/vkvg-svg.h
index acf4969..e35e168 100644
--- a/include/vkvg-nsvg.h
+++ b/include/vkvg-svg.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+ * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
*
* 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
@@ -19,13 +19,38 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#ifndef VKVG_NSVG_H
-#define VKVG_NSVG_H
+#ifndef VKVG_SVG_H
+#define VKVG_SVG_H
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ * @brief load svg file into @ref surface
+ *
+ * Create a new vkvg surface by loading a SVG file.
+ * @param dev The vkvg @ref device used for creating the surface.
+ * @param filePath The path of the SVG file to load.
+ * @param width force the rendering width, if 0 autosize from svg.
+ * @param height force the rendering height, if 0 autosize from svg.
+ * @return The new vkvg surface with the loaded SVG drawing as content, or null if an error occured.
+ */
+vkvg_public
+VkvgSurface vkvg_surface_create_from_svg(VkvgDevice dev, uint32_t width, uint32_t height, const char* filePath);
+/**
+ * @brief create surface from svg fragment
+ *
+ * Create a new vkvg surface by parsing a string with a valid SVG fragment passed as argument.
+ * @param dev The vkvg device used for creating the surface.
+ * @param width force the rendering width, if 0 autosize from svg.
+ * @param height force the rendering height, if 0 autosize from svg.
+ * @param fragment The SVG fragment to parse.
+ * @return The new vkvg surface with the parsed SVG fragment as content, or null if an error occured.
+ */
+vkvg_public
+VkvgSurface vkvg_surface_create_from_svg_fragment(VkvgDevice dev, uint32_t width, uint32_t height, char* svgFragment);
+#ifndef VKVG_SVG
/*! @defgroup nsvg Nano SVG
* @brief Render SVG drawings
*
@@ -44,26 +69,6 @@ extern "C" {
*/
typedef struct NSVGimage NSVGimage;
/**
- * @brief load svg file into @ref surface
- *
- * Create a new vkvg surface by loading a SVG file.
- * @param dev The vkvg @ref device used for creating the surface.
- * @param filePath The path of the SVG file to load.
- * @return The new vkvg surface with the loaded SVG drawing as content, or null if an error occured.
- */
-vkvg_public
-VkvgSurface vkvg_surface_create_from_svg(VkvgDevice dev, const char* filePath);
-/**
- * @brief create surface from svg fragment
- *
- * Create a new vkvg surface by parsing a string with a valid SVG fragment passed as argument.
- * @param dev The vkvg device used for creating the surface.
- * @param fragment The SVG fragment to parse.
- * @return The new vkvg surface with the parsed SVG fragment as content, or null if an error occured.
- */
-vkvg_public
-VkvgSurface vkvg_surface_create_from_svg_fragment(VkvgDevice dev, char* fragment);
-/**
* @brief load svg file
*
* Load basic svg file and store datas in a #NSVGimage structure. This structure
@@ -124,3 +129,4 @@ void vkvg_render_svg (VkvgContext ctx, NSVGimage* svg, char* subId);
#endif
#endif
+#endif
diff --git a/src/nanosvg.h b/src/nsvg/nanosvg.h
index 809bc87..809bc87 100644
--- a/src/nanosvg.h
+++ b/src/nsvg/nanosvg.h
diff --git a/src/vkvg_nsvg.c b/src/nsvg/vkvg_nsvg.c
index 70d2386..70d2386 100644
--- a/src/vkvg_nsvg.c
+++ b/src/nsvg/vkvg_nsvg.c
diff --git a/src/vkvg_context.c b/src/vkvg_context.c
index 5f51734..b551227 100644
--- a/src/vkvg_context.c
+++ b/src/vkvg_context.c
@@ -585,6 +585,22 @@ vkvg_status_t vkvg_rounded_rectangle (VkvgContext ctx, float x, float y, float w
return VKVG_STATUS_SUCCESS;
}
+void vkvg_rounded_rectangle2 (VkvgContext ctx, float x, float y, float w, float h, float rx, float ry){
+ vkvg_move_to (ctx, x+rx, y);
+ vkvg_line_to (ctx, x+w-rx, y);
+ vkvg_elliptic_arc(ctx, x+w, y+ry, false, true, rx, ry, 0);
+
+ vkvg_line_to (ctx, x+w, y+h-ry);
+ vkvg_elliptic_arc(ctx, x+w-rx, y+h, false, true, rx, ry, 0);
+
+ vkvg_line_to (ctx, x+rx, y+h);
+ vkvg_elliptic_arc(ctx, x, y+h-ry , false, true, rx, ry, 0);
+
+ vkvg_line_to (ctx, x, y+ry);
+ vkvg_elliptic_arc(ctx, x+rx, y , false, true, rx, ry, 0);
+
+ vkvg_close_path(ctx);
+}
static const VkClearAttachment clearStencil = {VK_IMAGE_ASPECT_STENCIL_BIT, 1, {{{0}}}};
static const VkClearAttachment clearColorAttach = {VK_IMAGE_ASPECT_COLOR_BIT, 0, {{{0}}}};
@@ -1336,19 +1352,3 @@ void vkvg_ellipse (VkvgContext ctx, float radiusX, float radiusY, float x, float
vkvg_curve_to (ctx, topLeftX, topLeftY, bottomLeftX, bottomLeftY, bottomCenterX, bottomCenterY);
vkvg_close_path (ctx);
}
-void vkvg_rounded_rectangle2 (VkvgContext ctx, float x, float y, float w, float h, float rx, float ry){
- vkvg_move_to (ctx, x+rx, y);
- vkvg_line_to (ctx, x+w-rx, y);
- vkvg_elliptic_arc(ctx, x+w, y+ry, false, true, rx, ry, 0);
-
- vkvg_line_to (ctx, x+w, y+h-ry);
- vkvg_elliptic_arc(ctx, x+w-rx, y+h, false, true, rx, ry, 0);
-
- vkvg_line_to (ctx, x+rx, y+h);
- vkvg_elliptic_arc(ctx, x, y+h-ry , false, true, rx, ry, 0);
-
- vkvg_line_to (ctx, x, y+ry);
- vkvg_elliptic_arc(ctx, x+rx, y , false, true, rx, ry, 0);
-
- vkvg_close_path(ctx);
-}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a0a0569..e281c64 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -33,6 +33,7 @@ TARGET_LINK_LIBRARIES(tests_common
${Vulkan_LIBRARIES}
${GLFW3_LIBRARY}
vkvg
+ $<$<BOOL:${VKVG_SVG}>:vkvg-svg>
)
file(GLOB_RECURSE DATAS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "data/*")
diff --git a/tests/svg.c b/tests/svg.c
index dd4fa8a..dd535da 100644
--- a/tests/svg.c
+++ b/tests/svg.c
@@ -1,17 +1,16 @@
#include "test.h"
-#include "string.h" //for nanosvg
-#include "vkvg-nsvg.h"
+#include "vkvg-svg.h"
static float rotation = 0.f;
static const char* path = "data/tiger.svg";
-void test_svg_surface() {
- VkvgSurface svgSurf = vkvg_surface_create_from_svg(device, path);
+void svg_surface() {
+ VkvgSurface svgSurf = vkvg_surface_create_from_svg(device, test_width, test_height, path);
VkvgContext ctx = vkvg_create(surf);
- vkvg_set_source_rgb(ctx,0,0,0);
+ vkvg_set_source_rgb(ctx,1,1,1);
vkvg_paint(ctx);
vkvg_set_source_surface(ctx, svgSurf, 0,0);
@@ -20,8 +19,8 @@ void test_svg_surface() {
vkvg_destroy(ctx);
vkvg_surface_destroy(svgSurf);
}
-
-void test_nsvg() {
+#ifndef VKVG_SVG
+void nsvg() {
NSVGimage* svg = nsvg_load_file(device, path);
if (svg == NULL) {
fprintf (stderr, "svg file not found: %s", path);
@@ -42,9 +41,13 @@ void test_nsvg() {
nsvg_destroy(svg);
}
+#endif
int main(int argc, char *argv[]) {
no_test_size = true;
- PERFORM_TEST (test_nsvg, argc, argv);
+ PERFORM_TEST (svg_surface, argc, argv);
+#ifndef VKVG_SVG
+ PERFORM_TEST (nsvg, argc, argv);
+#endif
return 0;
}