Skip to Content
SVG Text Layout
book

SVG Text Layout

by Amelia Bellamy-Royds, Kurt Cagle
October 2015
Intermediate to advanced
232 pages
5h 1m
English
O'Reilly Media, Inc.
Content preview from SVG Text Layout

Chapter 9. Beyond Straight Lines

Baselines ensure that glyphs are positioned to create a pleasing line of text. However, we’ve already said that, in graphical layout, you don’t always want text to display in perfectly straight lines. Sometimes it’s fun to make text move out of those boring lines and into more complex curves—circles, spirals, around the edges of various objects, and so forth.

This chapter introduces the <textPath> element, which allows you to use SVG path geometry to describe complex text layouts.

Creating Curved Text

We’ve shown (in Chapter 5) how you can position and rotate individual characters. For some simple designs, that’s enough. Example 9-1 spaces the letters of the word “Sunrise” in a semicircle, each letter positioned every 30° and rotated to match, as shown in Figure 9-1.

Example 9-1. Arranging letters around a shape with character position attributes
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xml:lang="en"
     width="4in" height="2.3in" viewBox="0 0 400 230">
    <title>Text Positioned in a Curve</title>
    <style type="text/css">
        text {
            font: bold italic 48px "Times New Roman", Times, serif;
            fill: gold;
            stroke: orangeRed;
        }
    </style>
    <rect fill="#CEE" width="100%" height="100%" />
    <g transform="translate(200,180)">                1
        <text x="-150 -130 -75 0 75 130 150"
              y="0 -75 -130 -150 -130 -75 0"
              rotate="-90 -60 -30 0 30 60 90"
              >Sunrise ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

SVG Colors, Patterns & Gradients

SVG Colors, Patterns & Gradients

Amelia Bellamy-Royds, Kurt Cagle
Mastering SVG

Mastering SVG

Rob Larsen
Building Web Applications with SVG

Building Web Applications with SVG

Jon Frost David Dailey and Domenico Strazzullo

Publisher Resources

ISBN: 9781491933817Errata Page