SVG Text Layout
by Amelia Bellamy-Royds and Kurt Cagle
Copyright 2016 Amelia Bellamy-Royds, Kurt Cagle. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editor: Meg Foley
- Production Editor: Colleen Lobner
- Copyeditor: Jasmine Kwityn
- Proofreader: James Fraleigh
- Indexer: Amelia Bellamy-Royds
- Interior Designer: David Futato
- Cover Designer: Ellie Volckhausen
- Illustrator: Rebecca Demarest
- November 2015: First Edition
Revision History for the First Edition
- 2015-10-20: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491933824 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. SVG Text Layout, the cover image of a Cabots tragopan, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-93382-4
[LSI]
Preface
Scalable Vector Graphics (SVG) consist of a markup language and associated style rules for defining images and diagrams. SVG is an image format, and for most people, text isnt the first thing they think of when considering the uses of SVG. From the beginning, however, a key feature of SVG has been its ability to encode text in a machine-readable form. Because SVG itself is a text-based markup language, the text characters in an SVG file can be viewed and edited in any text editor.
This book takes a deep dive into the use of text within SVG. It explores the creative possibilities, but also the potential pitfalls. It describes the basics, but also shows how you can use SVG to generate complex layouts. And, unfortunately, it also outlines the many inconsistencies and limitations of web browser implementations of SVG text (as of mid-2015, when this book was written).
This book was born from another project, an introduction to using SVG on the Web. In order to keep that book a manageable lengthand keep it suitable for introductory audiencesmany details and complexities had to be skimmed over. But those details and complexities add up to the full, wonderful potential of SVG as a graphics format. Once you understand the basics of SVG, you can start thinking about creating more intricate designs and more creative effects.
What Well Cover
If youre reading this, hopefully you are already familiar with the basics of SVG: how to define a graphic as a set of shapes, and how to use that graphic either as a standalone image file or as markup in an HTML page. It will also help if you are familiar with the basics of CSS-styled HTML text, as SVG text builds upon the basic CSS style rules.
The book starts with a brief overview of how computers display text content, and then steadily introduces the many ways SVG allows you to control the appearance of text:
reviews the basics of laying out text in word processors and websites, and introduces much of the technical terminology used to describe text.
introduces the SVG element and the basic attributes for positioning simple text labels within a graphic, including the particular issues of sizing text within a scalable coordinate system.
briefly covers SVGs fill
and stroke
properties for controlling the visual appearance of text.
gets into more complex text layouts, using formatted poetry as examples.
explores SVGs ability to control the position and orientation of individual text characters.
introduces the text-anchor
property and discusses how it affects the alignment of text.
considers the particular issues of multidirectional text, including right-to-left horizontal text and vertical text.
introduces the properties that control the vertical alignment of horizontal text and the horizontal alignment of vertical text.
looks at the element and how it can be used to create curved or complex text layouts.
explores fonts and their impact on SVG text, including the use of the @font-face
rule to incorporate web fonts in your SVG graphics online.
looks at the textLength
attribute and font-size-adjust
property, which can be used to standardize text layout when you dont have full control over the fonts used; the chapter also describes decorative uses for textLength
.
Finally, introduces the SVG element, and shows how it can be used to include CSS-formatted HTML text within an SVG image.
To complete the book, summarizes the related style properties.
About This Book
Whether youre casually flipping through the book, or reading it meticulously from cover to cover, you can get more from it by understanding the following little extras used to provide additional information.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
Tips like this will be used to highlight particularly tricky aspects of SVG, or simple shortcuts that might not be obvious at first glance.
Note
Notes like this will be used for more general asides and interesting background information.
Warning
Warnings like this will highlight compatibility problems between different web browsers (or other software), or between SVG as an XML file versus SVG in HTML pages.
In addition, sidebars like the following will introduce supplemental information:
A Brief Aside
Future Focus sidebars will look at proposed features that arent yet standardized, or new standards that arent widely implemented.
Although these sidebars are not absolutely essential for understanding SVG colors, patterns, and gradients, they will hopefully add important context when planning a complete web project.
Using Code Examples
Supplemental material (code examples and figures) is available for download as a zip archive or Git repository: