-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add doc about advanced text features #105
Open
joachimheintz
wants to merge
3
commits into
cduck:master
Choose a base branch
from
joachimheintz:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -775,6 +775,112 @@ d.append(dw.Text('Some text in Georgia.', 30, 10, 115, font_family='Georgia')) | |
 | ||
|
||
|
||
### Advanced Text Features | ||
|
||
The text properties which are described in this section are currently (drawsvg 2.2.0) | ||
not provieded by the internal rendering. The solution for now is to export an svg file | ||
which is then rendered by inkscape. | ||
|
||
#### White Space | ||
White space is preserved with the `white__space='pre'` property. (See [W3C](https://www.w3.org/TR/css-text-3/#white-space-property) for all options.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: I think this should be |
||
|
||
```python | ||
d = dw.Drawing(300,100,id_prefix='whitespace') | ||
d.append(dw.Text('white space not preserved',14,30,30)) | ||
d.append(dw.Text('white space preserved',14,30,60,white_space='pre')) | ||
d.save_svg('white-space.svg') | ||
from os import system | ||
system('inkscape -o 04_whitespace.png white-space.svg') | ||
``` | ||
|
||
 | ||
|
||
|
||
#### Wrapping Text: 'inline-size' | ||
|
||
See [W3C](https://www.w3.org/TR/SVG/text.html#InlineSize) for details. | ||
|
||
```python | ||
d = dw.Drawing(300,100,id_prefix='inlinesize') | ||
t = 'This text wraps at 200 pixels.' | ||
x,y = 50,30 | ||
d.append(dw.Text(t,20,x,y,style='font-style: sans-serif; inline-size: 200px;')) | ||
d.append(dw.Line(x,0,x,100,stroke='gray')) | ||
d.append(dw.Line(x+200,0,x+200,100,stroke='gray')) | ||
d.save_svg('inline-size.svg') | ||
from os import system | ||
system('inkscape -o 04_inlinesize.png inline-size.svg') | ||
``` | ||
|
||
 | ||
|
||
|
||
#### Text Inside a Shape | ||
|
||
See [W3C](https://www.w3.org/TR/SVG/text.html#TextShapeInside) for details. | ||
|
||
```python | ||
d = dw.Drawing(300,300,id_prefix='shapeinside') | ||
t = 'Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat.' | ||
x,y = 50,30 | ||
d.append(dw.Circle(150,150,120,stroke='gray',fill='none',id='wrap')) | ||
d.append(dw.Text(t,20,0,0,style="""font-style: sans-serif; | ||
text-align: center; | ||
shape-inside: url(#wrap);""")) | ||
d.save_svg('shape-inside.svg') | ||
from os import system | ||
system('inkscape -o 04_shapeinside.png shape-inside.svg') | ||
``` | ||
|
||
 | ||
|
||
|
||
#### The 'shape-subtract' property | ||
|
||
The result is here not completely according to [W3C](https://www.w3.org/TR/SVG2/text.html#TextShapeSubtract) | ||
because the justification does not work, but the `shape-subtract` works. | ||
|
||
```python | ||
d = dw.Drawing(450,300,id_prefix='shapesubtract') | ||
d.append(dw.Rectangle(25,25,225,175,fill='white',stroke='black',id='rect1')) | ||
d.append(dw.Rectangle(200,125,225,150,fill='white',stroke='black',id='rect2',style="shape-margin:25px;")) | ||
t = 'Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat.' | ||
d.append(dw.Text(t,12,0,0,style="""shape-inside:url(#rect1); | ||
shape-subtract:url(#rect2); | ||
shape-padding:25px; | ||
font-family:DejaVu Sans; | ||
text-align:justified; | ||
line-height:110%""")) | ||
d.append(dw.Text(t,12,0,0,style="""shape-inside:url(#rect2); | ||
shape-padding:25px; | ||
font-family:DejaVu Sans; | ||
text-align:justified; | ||
line-height:110%""")) | ||
d.save_svg('shape-subtract.svg') | ||
from os import system | ||
system('inkscape -o 04_shapesubtract.png shape-subtract.svg') | ||
d | ||
``` | ||
|
||
 | ||
|
||
#### The 'shape-padding' property | ||
|
||
Again the justification is not correct in the inkscape output but the padding works as expected. | ||
|
||
```python | ||
d = dw.Drawing(300,300,id_prefix='shapepadding') | ||
d.append(dw.Circle(150,150,125,fill='none',stroke='black',id='circle')) | ||
t = 'This is a sample of wrapped text in SVG 2! There should be 25 pixel padding around the text. The text is justified on both sides. It looks good!' | ||
d.append(dw.Text(t,18,0,0,style='shape-inside: url(#circle); shape-padding: 25px; font-family: DejaVu Sans; text-align: justified; line-height: 110%;')) | ||
d.save_svg('shape-padding.svg') | ||
from os import system | ||
system('inkscape -o 04_shapepadding.png shape-padding.svg') | ||
d | ||
``` | ||
|
||
 | ||
|
||
|
||
## Gradient, Clip, Mask | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add that current browsers also do not support these attributes.