Rev 531 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2007 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* Author: Steve Ratcliffe
* Create date: Dec 18, 2007
*/
package test.display;
import uk.me.parabola.imgfmt.app.ImgFileReader;
import java.io.PrintStream;
import java.util.List;
import java.util.ArrayList;
/**
* For displaying polygons in a typ file.
*
* @author Steve Ratcliffe
*/
public class PolygonDisplayer
extends TypSectionDisplayer
{
private final ImgFileReader reader
;
private final PrintStream out
;
private final List<Integer> offsets =
new ArrayList<Integer>();
public PolygonDisplayer
(ImgFileReader reader,
PrintStream outStream
) {
this.
reader = reader
;
this.
out = outStream
;
}
public void print
() {
printPolygonDefs
();
}
private void printPolygonDefs
() {
reader.
position(0x47
); // sect4
int start = reader.
get4();
int itemsize = reader.
get2u();
int size = reader.
get4();
reader.
position(0x27
); // sect1
reader.
get4();
printTypes
(start, itemsize, size
);
reader.
position(0x27
);
int stylestart = reader.
get4();
size = reader.
get4();
printStyles
(stylestart, size
);
}
private void printStyles
(int start,
int size
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Polygon styles");
d.
setSectStart(start
);
for (int i =
0; i
< offsets.
size(); i++
) {
int off = start + offsets.
get(i
);
int end = start +
((i
< offsets.
size() -
1) ? offsets.
get(i +
1) : size
);
reader.
position(off
);
int flagAndScheme = d.
byteValue("Color scheme: 0x%x");
int colorscheme = flagAndScheme
& 0xf
;
int flags = flagAndScheme
& 0xf0
;
printColourScheme
(d, colorscheme
);
if ((colorscheme
& 0x8
) !=
0)
printBitmap
(d
);
if ((flags
& 0x10
) !=
0) // Has text
printLabels
(d
);
if ((flags
& 0x20
) !=
0) // Font info
printFontInfo
(d
);
d.
rawValue((int) (end - reader.
position()));
d.
gap();
}
d.
print(out
);
}
private void printBitmap
(Displayer d
) {
d.
rawValue(128,
"Pixmap");
}
private void printTypes
(int start,
int itemsize,
int size
) {
Displayer d =
new Displayer
(reader
);
d.
setTitle("Polygon types");
d.
setSectStart(start
);
reader.
position(start
);
long end = start+size
;
for (long pos = start
; pos
< end
; pos += itemsize
) {
DisplayItem item = d.
item();
int typ_id = reader.
get2u();
item.
setBytes2(typ_id
);
item.
addText("type %x",
(typ_id
>> 5));
// Get the offset into the shape style section.
item = d.
intItem(itemsize -
2);
int off = item.
getValue();
item.
addText("Style at offset %04x", off
);
offsets.
add(off
);
}
d.
print(out
);
}
}