Debian Codegraph @

src/uk/me/parabola/imgfmt/app/typ/TypLine.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
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 * A line as read from a typ.txt file.
21 *
22 * @author Steve Ratcliffe
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 * This is slightly different to the polygon case, but not much.
35 *
36 * The line width is held in the first byte along with the type.
37 * The colour scheme does not have a bit to say if a bitmap is used,
38 * as you can always have one.
39 *
40 * There is a border width that can be specified.
41 *
42 * @param encoder For the labels.
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 // The labels have a length byte to show the number of bytes following. There is
77 // also a flag in the length. The strings have a language number proceeding them.
78 // The strings themselves are null terminated.
79 if ((flags & F_LABEL) != 0)
80 writeLabelBlock(writer, encoder);
81
82 // The extension section hold font style and colour information for the labels.
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 }