Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextD for apply dx and dy to text #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/ajstarks/svgo
module github.com/guigui64/svgo

go 1.15

Expand Down
18 changes: 18 additions & 0 deletions svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ func (svg *SVG) Image(x int, y int, w int, h int, link string, s ...string) {
svg.printf(`<image %s %s %s`, dim(x, y, w, h), href(link), endstyle(s, emptyclose))
}

// ImageNoRatio places at x,y (upper left hand corner), the image with
// width w, and height h, referenced at link, no ratio, with optional style.
// Standard Reference: http://www.w3.org/TR/SVG11/struct.html#ImageElement
func (svg *SVG) ImageNoRatio(x int, y int, w int, h int, link string, s ...string) {
svg.printf(`<image %s %s %s preserveAspectRatio="none"`, dim(x, y, w, h), href(link), endstyle(s, emptyclose))
}

// Text places the specified text, t at x,y according to the style specified in s
// Standard Reference: http://www.w3.org/TR/SVG11/text.html#TextElement
func (svg *SVG) Text(x int, y int, t string, s ...string) {
Expand All @@ -411,6 +418,14 @@ func (svg *SVG) Text(x int, y int, t string, s ...string) {
svg.println(`</text>`)
}

// Text places the specified text, t at x,y according to the style specified in s
// Standard Reference: http://www.w3.org/TR/SVG11/text.html#TextElement
func (svg *SVG) TextD(x int, y int, dx, dy string, t string, s ...string) {
svg.printf(`<text %s %s %s`, loc(x, y), d(dx, dy), endstyle(s, ">"))
xml.Escape(svg.Writer, []byte(t))
svg.println(`</text>`)
}

// 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) {
Expand Down Expand Up @@ -1032,6 +1047,9 @@ func ptag(x int, y int) string { return fmt.Sprintf(`<path d="M%s`, coord(x, y))
// loc returns the x and y coordinate attributes
func loc(x int, y int) string { return fmt.Sprintf(`x="%d" y="%d"`, x, y) }

// d returns the dx and dy offset attributes
func d(dx, dy string) string { return fmt.Sprintf(`dx="%s" dy="%s"`, dx, dy) }

// href returns the href name and attribute
func href(s string) string { return fmt.Sprintf(`xlink:href="%s"`, s) }

Expand Down