Giter VIP home page Giter VIP logo

Comments (4)

ajstarks avatar ajstarks commented on May 19, 2024

This looks interesting. How about:

// Textspan begins text, assuming a tspan will be included, end with TextEnd()
// Standard Reference: https://www.w3.org/TR/SVG11/text.html#TSpanElement
func (svg *SVG) Textspan(x int, y int, t string, s ...string) {
	svg.printf(`<text %s %s`, loc(x, y), endstyle(s, ">"))
	xml.Escape(svg.Writer, []byte(t))
}

// Span makes styled spanned text, should be proceeded by Textspan
// Standard Reference: https://www.w3.org/TR/SVG11/text.html#TSpanElement
func (svg *SVG) Span(t string, s ...string) {
	if len(s) == 0 {
		xml.Escape(svg.Writer, []byte(t))
		return
	}
	svg.printf(`<tspan %s`, endstyle(s, ">"))
	xml.Escape(svg.Writer, []byte(t))
	svg.printf(`</tspan>`)
}

// TextEnd ends spanned text
// Standard Reference: https://www.w3.org/TR/SVG11/text.html#TSpanElement
func (svg *SVG) TextEnd() {
	svg.println(`</text>`)
}

from svgo.

ajstarks avatar ajstarks commented on May 19, 2024

Example use:

package main

import (
	"os"

	svg "github.com/ajstarks/svgo"
)

func main() {
	width := 500
	height := 500
	canvas := svg.New(os.Stdout)
	canvas.Start(width, height)
	canvas.Circle(width/2, height/2, 100)
	canvas.Gstyle("text-anchor:middle;fill:white")
	canvas.Textspan(width/2, height/2, "Hello ", "font-size:30px")
	canvas.Span("SVG", "font-size:50px")
	canvas.TextEnd()
	canvas.Gend()
	canvas.End()
}

image

from svgo.

ajstarks avatar ajstarks commented on May 19, 2024

Added with 1f3ef52

from svgo.

Iriel avatar Iriel commented on May 19, 2024

Lovely thanks!

from svgo.

Related Issues (20)

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.