Skip to content

Commit 9a9c9f3

Browse files
committed
Allow position/size/orientation for text blocks
1 parent a3d7b4f commit 9a9c9f3

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

Help/text.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,51 @@ You can use the `fill` or `extrude` commands to turn these paths into a solid me
3232

3333
## Size
3434

35-
To adjust the text size, you can use the [scale](transforms.md#relative-transforms) command prior to calling text:
35+
To adjust the text size, you can use the [size](transforms.md#size) option:
3636

3737
```swift
38-
scale 2 // increase text size by 200%
39-
text "Hello World"
38+
text {
39+
size 2 // increase text size by 200%
40+
text "Hello World"
41+
}
4042
```
4143

42-
Alternatively, for filled or extruded text, you can set the size directly in the shape block using the [size](transforms.md#size) option:
44+
You can resize the text non-uniformly by passing separate width and height values for the size:
45+
46+
```swift
47+
text {
48+
size 2 1.5 // set width to 200% and height to 150%
49+
text "Hello World"
50+
}
51+
```
52+
53+
Alternatively, for extruded text, you can set the size in the shape block instead, which allows you to also set the depth at the same time:
4354

4455
```swift
4556
extrude {
46-
size 2 0.5 // 200% sized text, with 50% depth
57+
size 2 2 0.5 // 200% sized text, with 50% depth
4758
text "Hello World"
4859
}
4960
```
5061

5162
## Position and Orientation
5263

53-
To adjust the text position and orientation, use the [translate and rotate](transforms.md#relative-transforms) commands:
64+
To adjust the text position and orientation, use the [position](transforms.md#position) and [orientation](transforms.md#orientation) commands:
5465

5566
```swift
56-
translate 2 1 // move text 2 units to the right and 1 unit u
57-
rotate 0.5 // rotate by 90 degrees
58-
text "Hello World"
67+
text {
68+
position 2 1 // move text 2 units to the right and 1 unit up
69+
orientation 0.5 // rotate by 90 degrees
70+
"Hello World"
71+
}
5972
```
6073

61-
Or for filled or extruded text, you can set the [position](transforms.md#position) and [orientation](transforms.md#orientation) options inside the shape block:
74+
Or for filled or extruded text, you can set these on the containing shape block instead:
6275

6376
```swift
64-
extrude {
77+
fill {
6578
position 1 2 3 // set the position in 3D space
66-
orientation 0.5 0 0 // set a 3D rotation
79+
orientation 0 0.5 0 // rotate around the Y axis
6780
text "Hello World"
6881
}
6982
```

ShapeScript/StandardLibrary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extension Dictionary where Key == String, Value == Symbol {
179179
"text": .block(.text) { context in
180180
let text = context.children.map { $0.value as! String }.joined(separator: "\n")
181181
let paths = Path.text(text, font: context.font, detail: context.detail / 8)
182-
return .tuple(paths.map { .path($0) })
182+
return .tuple(paths.map { .path($0.transformed(by: context.transform)) })
183183
},
184184
]
185185

@@ -302,7 +302,7 @@ extension Dictionary where Key == String, Value == Symbol {
302302
static let builder: Symbols = _merge(primitive, transforms)
303303
static let group: Symbols = _merge(primitive, transforms)
304304
static let path: Symbols = _merge(global, transforms, points)
305-
static let text: Symbols = global
305+
static let text: Symbols = primitive
306306
static let definition: Symbols = root
307307
static let all: Symbols = _merge(root, primitive, points)
308308
}

ShapeScriptTests/InterpreterTests.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,6 @@ class InterpreterTests: XCTestCase {
451451
}
452452
}
453453

454-
func testPositionInvalidInText() {
455-
let program = """
456-
text {
457-
position 1 0 0
458-
"Hello"
459-
}
460-
"""
461-
XCTAssertThrowsError(try evaluate(parse(program), delegate: nil)) { error in
462-
let error = try? XCTUnwrap(error as? RuntimeError)
463-
guard case let .unknownSymbol("position", options)? = error?.type else {
464-
XCTFail()
465-
return
466-
}
467-
print(options)
468-
XCTAssert(!options.contains("option"))
469-
}
470-
}
471-
472454
func testSetPositionWithTupleConstant() throws {
473455
let program = """
474456
define foo (1 0 0) 0

0 commit comments

Comments
 (0)