| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
package com.github.weisj.jsvg.nodes.text; |
| 23 |
|
| 24 |
import java.awt.geom.AffineTransform; |
| 25 |
import java.util.Objects; |
| 26 |
|
| 27 |
import org.jetbrains.annotations.NotNull; |
| 28 |
import org.jetbrains.annotations.Nullable; |
| 29 |
|
| 30 |
import com.github.weisj.jsvg.renderer.RenderContext; |
| 31 |
import com.github.weisj.jsvg.renderer.output.TextOutput; |
| 32 |
|
| 33 |
public abstract class GlyphRunTextOutput implements TextOutput { |
| 34 |
|
| 35 |
private final StringBuilder codepoints = new StringBuilder(); |
| 36 |
private @Nullable AffineTransform glyphTransform; |
| 37 |
private @Nullable RenderContext context; |
| 38 |
|
| 39 |
protected abstract void glyphRun(@NotNull String codepoints, @NotNull AffineTransform glyphTransform, |
| 40 |
@NotNull RenderContext context); |
| 41 |
|
| 42 |
protected abstract void onTextStart(); |
| 43 |
|
| 44 |
protected abstract void onTextEnd(); |
| 45 |
|
| 46 |
@Override |
| 47 |
public void codepoint(@NotNull String codepoint, @NotNull AffineTransform glyphTransform, |
| 48 |
@NotNull RenderContext context) { |
| 49 |
if (this.context == null) { |
| 50 |
this.context = context; |
| 51 |
} |
| 52 |
if (this.glyphTransform == null) { |
| 53 |
this.glyphTransform = glyphTransform; |
| 54 |
} |
| 55 |
codepoints.append(codepoint); |
| 56 |
} |
| 57 |
|
| 58 |
private void reset() { |
| 59 |
context = null; |
| 60 |
codepoints.setLength(0); |
| 61 |
glyphTransform = null; |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public final void beginText() { |
| 66 |
reset(); |
| 67 |
onTextStart(); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void glyphRunBreak() { |
| 72 |
if (codepoints.length() == 0) return; |
| 73 |
glyphRun(codepoints.toString(), |
| 74 |
Objects.requireNonNull(glyphTransform), |
| 75 |
Objects.requireNonNull(context)); |
| 76 |
reset(); |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public final void endText() { |
| 81 |
glyphRunBreak(); |
| 82 |
onTextEnd(); |
| 83 |
} |
| 84 |
} |