Coder Social home page Coder Social logo

jsonvg's Introduction

JsonVG

JsonVG (Json Vector Graphics) is a vector graphics format based on JSON. It always starts with the magic number "jsonvg(0)", followed by a Document object encoded in JSON. The specification is given in terms of TypeScript interfaces and comments explaining the various attributes.

s2jsonvg

...is a command-line utility that can be used to convert basic SVG files into JsonVG files.

Usage: s2jsonvg input.svg output.jsonvg

Specification:

interface Document {
	/** The width of the document in pixels */
	width: number;
	
	/** The height of the document in pixels */
	height: number;
	
	/** The shapes that make up the document */
	content: Shape[];
}

/** 4 points representing a cubic bezier curve or 2 points representing a line */
type BezierCurve = [Point, Point, Point, Point] | [Point, Point];

/** A point in the form [x, y] where x and y are the position of the point in pixels, from the top-left going right and down */
type Point = [number, number];

interface Shape {
	/** A list of segments that make up the shape */
	segments: BezierCurve[];
	
	/** Specifies the fill style of the shape */
	fill: FillStyle;
	
	/** Specifies the stroke style of the shape */
	stroke: StrokeStyle;
}

/** A color given in form [R, G, B, A], where all values range from 0.0 to 1.0, and alpha represents opacity */
type Color = [number, number, number, number];

interface FillStyle {
	/** The type of fill */
	type: "solid" | "none";
	
	/** If solid, the color of the fill */
	color?: Color = [0, 0, 0, 1];
}

interface StrokeStyle {
	/** The type of stroke */
	type: "solid" | "none";
	
	/** If solid, the location of the stroke */
	location?: "inner" | "edge" | "outer" = "edge";
	
	/**
	 * If solid, the way that line segments will be joined
	 * Note that two line segments will be joined if the end point of one is equivalent to the start point of the other
	 */
	join?: "miter" | "round" | "bevel" = "miter";
	
	/**
	 * If solid, the way that line segments will be capped
	 */
	cap?: "sharp" | "round" = "sharp";
	
	/** If solid, the width of the stroke */
	weight?: number = 1;
	
	/** If solid, the color of the stroke */
	color?: Color = [0, 0, 0, 1];
}

Example:

jsonvg(0){
	"width": 100,
	"height": 100,
	"content": [
		{
			"segments": [
				[[0, 0], [0, 100]],
				[[0, 100], [100, 100]],
				[[100, 100], [100, 0], [50, 50], [0, 0]]
			],
			"fill": {
				"type": "solid",
				"color": [0.752, 0.432, 0.192, 1.0]
			},
			"stroke": {
				"type": "solid",
				"location": "inner",
				"join": "round",
				"weight": 4,
				"color": [0.0, 0.0, 0.0, 1.0]
			}
		}
	]
}

jsonvg's People

Contributors

brianush1 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

magicianred

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.