Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

SVG Native viewer is a library that parses and renders SVG Native documents

License

NotificationsYou must be signed in to change notification settings

adobe/svg-native-viewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CircleCI

SVG Native viewer is a library that parses and renders SVG Nativedocuments.

SVG Native

SVG Native is an upcoming specification of the SVG WG based onSVGOpenType. SVG Native will be a strict subset of SVG 1.1 and SVG 2.0.

Supported features in SVG Native (in comparison to SVG1.1/SVG2)

  • No stylesheet support (CSS/XSL) with the exception of the basicinheritance model and the following presentation attributes:
    • clip-path
    • clip-rule
    • color
    • display
    • fill
    • fill-opacity
    • fill-rule
    • opacity
    • stroke
    • stroke-dasharray
    • stroke-dashoffset
    • stroke-linecap
    • stroke-linejoin
    • stroke-miterlimit
    • stroke-opacity
    • stroke-width
    • stop-color
    • stop-opacity
    • visibility
  • CSS properties do not support any default property values likeinherit,initial,unset, orrevert.
  • No support for scripting, interactions, events, animations, filters,masks, patterns, texts.
  • No support for inner<svg> or<symbol> elements.
  • No support for XML namespaces with the exception of the SVG namespaceand the Xlink namespace.
  • No support ofobjectBoundingBox ongradientUnits orclipPathUnits.
  • Thevar() CSS value function is limited to the CSS propertiesfill,stroke,stop-color andcolor. Only color values areallowed.currentColor is supported.

A valid SVG Native document is always a valid SVG1.1/2.0 document.

SVG Native Viewer Library

SVG Native Viewer is a C++11 based project and can either be includedin the source code of a client directly or linked statically ordynamically.

For rendering, SVG Native Viewer requires a rendering port. Alreadyexisting ports include:

  • StringSVGRenderer for testing purposes,
  • CGSVGRenderer a rendering port using CoreGraphics (Quartz 2D).
  • SkiaSVGRenderer a rendering port using Skia. (Skia requires a C++14 compatible compiler!)
  • CairoSVGRenderer a rendering port using Cairo Graphics.
  • GDIPlusSVGRenderer a rendering port using GDI+.
  • D2DSVGRenderer a rendering port using Direct2D.

New ports need to inherit fromSVGRenderer and implement thevirtual functions.

Here an example how to use SVG Native Viewer with SkiaSkiaSVGRenderer:

// Create the renderer objectauto renderer = std::make_shared<SVGNative::SkiaSVGRenderer>();// Create SVGDocument object and parse the passed SVG string.auto doc = std::unique_ptr<SVGNative::SVGDocument>(SVGNative::SVGDocument::CreateSVGDocument(svgInput.c_str(), renderer));// Setup SkSurface for drawingauto skRasterSurface = SkSurface::MakeRasterN32Premul(doc->Width(),                                                      doc->Height());auto skRasterCanvas = skRasterSurface->getCanvas();// Pass SkCanvas to renderer objectrenderer->SetSkCanvas(skRasterCanvas);// Pass drawing commands for SVG document to renderer.doc->Render();// Pass drawing commands for SVG document to renderer the element (and// its descendants)// with the XML ID "ref1".std::string id1{"ref1"}doc->Render(id1);// The Render() function may get called multiple times. This can be// used to render a combination of glyphs specified in the same SVG// document.std::string id2{"ref2"}doc->Render(id2);

Refer to the examples in theexample/ directory for other portexamples.

Requirements

Submodules

This repository uses submodules. To initiate and keep submodulesup-to-date run the following command:

git submodule update --init

Submodules are located in thethird_party/ directory. Used submodules:

  • stylesheet(optional) Needed if compiled with limited CSS style support(deprecated).
  • cpp-base64(optional) Needed by some ports for decoding base64 encoded rasterimage support.
  • boost_variant_property_tree(optional) Minimal version of Boost stripped down to therequirements ofvariant andproperty_tree. Used if Boost was notinstalled on the system.

Windows

Install:

  • CMake Download and run the installer
  • Boost Download the ZIP-package and extractthe package intoC:>\Program Files\boost_x.y.z\ (See below how tospecify a different Boost installation directory by a CMake option.)
  • MS Visual Studio 2017 orup Download andinstall with the installer. Make sure Visual C++ gets installed. (Youmaybe be able to use the "Community" version for free fornon-commercial/enterprise use. See the website from MS for licensedetails.)

OSX

With Homebrew:

brew install cmakebrew install llvmbrew install boost

LINUX

  • Apt
sudo apt-get install build-essential libboost-system-dev cmake

Building

Create project files

For Windows 64 bit:

cmake -Bbuild/win64 -H. -G "Visual Studio 15 2017 Win64"

For Windows 32 bit:

cmake -Bbuild/win32 -H. -G "Visual Studio 15 2017"

Omit-H when running in PowerShell.

For macOS

cmake -Bbuild/mac -H. -G "Xcode"

For Linux

cmake -Bbuild/linux -H.

On Linux you may choose to use GCC or Clang/LLVM. Add the following tothe command above to choose between one and the other:

  • -DCMAKE_CXX_COMPILER=g++ for GCC
  • -DCMAKE_CXX_COMPILER=clang for Clang/LLVM

On Windows you may choose to use Clang/LLVM as compiler. For help,follow the instructions of the linked MS Visual StudioLLVMExtension.Add -T "LLVM" to the project generation command above.

To specify a different Boost installation directory on Windows use thefollowing command:

  • -DBOOST_ROOT=X:\path\to\boost

The following arguments can be passed with the-D flag and theoptionsON orOFF:

  • LIB_ONLY Only compile the library without examples. DefaultOFF.
  • SHARED IfON, builds a dynamic library. Static otherwise. DefaultOFF.
  • PLATFORM_XML IfON, uses libxml2 or Epat if provided by thesystem. Otherwise RapidXML via boost. DefaultOFF.
  • TEXT adds theText port to the library. DefaultON.
  • CG adds theCoreGraphics/Quartz2D port to the library. DefaultOFF.
  • SKIA adds theSkia port to the library. DefaultOFF.
  • GDIPLUS adds theGDI+ port to the library. DefaultOFF.
  • D2D adds theDirect2D port to the library. DefaultOFF.
  • CAIRO adds theCairo Graphics port to the library. DefaultOFF.
  • TESTING enables automated testing using Google Tests. DefaultON.

To enable the deprecated CSS styling support:

  • STYLE adds limited, deprecated support for<style> element andstyle attribute. DefaultOFF.(This option will get removedeventually.)

The following example creates project files for the library with theText, CoreGraphics/Quartz2D and Skia port and the example applications.Example:

cmake -Bbuild/mac -H. -G "Xcode" -DCG=ON -DSKIA=ON

Note: For testing, build with theTEXT option set toON andLIB_ONLY option set toOFF. (The default for both.)

Build

Replacewin64 with your platform (mac for Xcode on macOS)

cmake --build build/win64 --config Release

Boost requirements

Only the header version of Boost is required. The following Boostfeatures are used:

  • Boost RapidXML(Can be replaced by libxml2.)
  • boost::variant to handle different SVG paint types offill andstroke as well as different color value types.
  • Boost string functions likeboost::tokenizer,boost::trim.(Onlyused by deprecated CSS<style> element parsing.)

Tests

SVG Native Viewer has two testing mechanisms. A python script that performs the renderings on theText port and compares the renderings with the existing ones and automated software testing using Google Tests framework.

Text port testing

To use the python script:

  1. Make sure your system has Python installed.
  2. By default, CMake creates the project files forSVGNativeViewerLib andtestSVGNative. Follow the steps above tobuild the test app.
  3. Run
python script/runTest.py --tests=test/

Here the argument list ofrunTest.py:

  • --test the folder with the test files.
  • --program the path totestSVGNative. If not provided uses thedefault, relative build path.
  • --debug Debug build or Release build oftestSVGNative. Onlyrelevant if--program was not set and defaults to--debug.

Google Test based testing

In order to build and run the tests, pass the argument-DTESTING=ON when running Cmake. Cmake will automatically download and build Google Tests and compile the tests. In order to run the tests you can runmake test or just usectest in the build folder.

Ultimately, we aim to improve software unit testing as well as add rendering tests to ensure that SVG Native Viewer's renderings are accurate.

Known limitations in SVG Native Viewer

  • preserveAspectRatio is not supported on the<svg> element yet.
  • Furthermore, there might be limitations on certain platforms. (E.g.missing gradient spread-method support on CoreGraphics.)

Contributing

Contributions are welcomed! Read theContributingGuide for more information.

Licensing

This project is licensed under the Apache V2 License. SeeLICENSE for more information.

About

SVG Native viewer is a library that parses and renders SVG Native documents

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp