| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package uk.me.parabola.imgfmt.app.typ; |
| 14 |
|
| 15 |
import java.nio.charset.CharsetEncoder; |
| 16 |
|
| 17 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class TypLine extends TypElement { |
| 25 |
private static final int F_LABEL = 0x1; |
| 26 |
private static final int F_USE_ROTATION = 0x2; |
| 27 |
private static final int F_EXTENDED = 0x4; |
| 28 |
|
| 29 |
private boolean useOrientation; |
| 30 |
private byte lineWidth; |
| 31 |
private byte borderWidth; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public void write(ImgFileWriter writer, CharsetEncoder encoder) { |
| 45 |
offset = writer.position(); |
| 46 |
|
| 47 |
byte flags = 0; |
| 48 |
|
| 49 |
if (!labels.isEmpty()) |
| 50 |
flags |= F_LABEL; |
| 51 |
if (fontStyle != 0 || dayFontColour != null) |
| 52 |
flags |= F_EXTENDED; |
| 53 |
if (!useOrientation) |
| 54 |
flags |= F_USE_ROTATION; |
| 55 |
|
| 56 |
int height = 0; |
| 57 |
if (xpm.hasImage()) |
| 58 |
height = xpm.getColourInfo().getHeight(); |
| 59 |
|
| 60 |
ColourInfo colourInfo = xpm.getColourInfo(); |
| 61 |
int scheme = colourInfo.getColourScheme() & 0x7; |
| 62 |
|
| 63 |
writer.put1u((scheme & 0x7) | (height << 3)); |
| 64 |
writer.put1u(flags); |
| 65 |
|
| 66 |
colourInfo.write(writer); |
| 67 |
if (xpm.hasImage()) |
| 68 |
xpm.writeImage(writer); |
| 69 |
|
| 70 |
if (height == 0) { |
| 71 |
writer.put1u(lineWidth); |
| 72 |
if ((scheme&~1) != 6) |
| 73 |
writer.put1u(lineWidth + 2*borderWidth); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
if ((flags & F_LABEL) != 0) |
| 80 |
writeLabelBlock(writer, encoder); |
| 81 |
|
| 82 |
|
| 83 |
if ((flags & F_EXTENDED) != 0) |
| 84 |
writeExtendedFontInfo(writer); |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
public void setUseOrientation(boolean useOrientation) { |
| 89 |
this.useOrientation = useOrientation; |
| 90 |
} |
| 91 |
|
| 92 |
public void setLineWidth(int val) { |
| 93 |
lineWidth = (byte) val; |
| 94 |
} |
| 95 |
|
| 96 |
public void setBorderWidth(int borderWidth) { |
| 97 |
this.borderWidth = (byte) borderWidth; |
| 98 |
} |
| 99 |
|
| 100 |
public void finish() { |
| 101 |
if (borderWidth != 0) |
| 102 |
xpm.getColourInfo().setHasBorder(true); |
| 103 |
} |
| 104 |
} |