source: trunk/src/org/expeditee/items/FrameBitmap.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 2.9 KB
Line 
1/**
2 * FrameBitmap.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items;
20
21import java.util.List;
22
23import org.expeditee.core.Colour;
24import org.expeditee.core.Image;
25import org.expeditee.gui.Frame;
26import org.expeditee.gui.FrameIO;
27
28//TODO tidy up the mess I caused with refresh during the period where I was going into XRay mode before saving
29
30public class FrameBitmap extends FramePicture {
31 public FrameBitmap(Text source, Image image){
32 super(source, image);
33 }
34
35 @Override
36 public boolean refresh() {
37 assert (_source.getLink() != null);
38 Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink());
39 // if the frame cant be found just use the current image
40 if (frame == null) {
41 return false;
42 }
43
44 List<Text> textList = frame.getBodyTextItems(false);
45 if (textList.size() == 0)
46 return false;
47 List<String> imageLines = textList.get(0).getTextList();
48 int width = 0;
49 int height = imageLines.size();
50 // Determine the image width by finding the widest line of text
51 for (String s : imageLines) {
52 if (s.length() > width)
53 width = s.length();
54 }
55
56 if(width == 0)
57 return false;
58
59 Image bi = Image.createImage(width, height);
60 // now set the bits on the image
61 final int transparent = (new Colour(0F, 0F, 0F, 0F)).getARGB32BitPacked();
62 final int main = _source.getPaintColor().getARGB32BitPacked();
63 final Colour c = _source.getPaintColor();
64 int currentColor = main;
65 int row = 0;
66 for (String s : imageLines) {
67 for (int i = 0; i < width; i++) {
68 currentColor = transparent;
69 if (i < s.length()) {
70 char currentPixel = s.charAt(i);
71 // Space is transparent as is 0
72 if (Character.isDigit(currentPixel)) {
73 int alpha = Math.round((currentPixel - '0') * (Colour.COMPONENT_MAX_VALUE / 10.0f));
74 currentColor = new Colour(c.getRed(), c.getGreen(), c
75 .getBlue(), alpha).getARGB32BitPacked();
76 }else if (currentPixel != ' ') {
77 currentColor = main;
78 }
79 }
80 bi.setPixel(i, row, Colour.fromARGB32BitPacked(currentColor));
81 }
82 row++;
83 }
84 _image = bi;
85
86 return true;
87 }
88
89 @Override
90 protected Picture createPicture() {
91 return new FrameBitmap((Text) _source.copy(), _image);
92 }
93
94 @Override
95 protected String getTagText() {
96 return "@b: ";
97 }
98}
Note: See TracBrowser for help on using the repository browser.