/** * FrameBitmap.java * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package org.expeditee.items; import java.util.List; import org.expeditee.core.Colour; import org.expeditee.core.Image; import org.expeditee.gui.Frame; import org.expeditee.gui.FrameIO; //TODO tidy up the mess I caused with refresh during the period where I was going into XRay mode before saving public class FrameBitmap extends FramePicture { public FrameBitmap(Text source, Image image){ super(source, image); } @Override public boolean refresh() { assert (_source.getLink() != null); Frame frame = FrameIO.LoadFrame(_source.getAbsoluteLink()); // if the frame cant be found just use the current image if (frame == null) { return false; } List textList = frame.getBodyTextItems(false); if (textList.size() == 0) return false; List imageLines = textList.get(0).getTextList(); int width = 0; int height = imageLines.size(); // Determine the image width by finding the widest line of text for (String s : imageLines) { if (s.length() > width) width = s.length(); } if(width == 0) return false; Image bi = Image.createImage(width, height); // now set the bits on the image final int transparent = (new Colour(0F, 0F, 0F, 0F)).getARGB32BitPacked(); final int main = _source.getPaintColor().getARGB32BitPacked(); final Colour c = _source.getPaintColor(); int currentColor = main; int row = 0; for (String s : imageLines) { for (int i = 0; i < width; i++) { currentColor = transparent; if (i < s.length()) { char currentPixel = s.charAt(i); // Space is transparent as is 0 if (Character.isDigit(currentPixel)) { int alpha = Math.round((currentPixel - '0') * (Colour.COMPONENT_MAX_VALUE / 10.0f)); currentColor = new Colour(c.getRed(), c.getGreen(), c .getBlue(), alpha).getARGB32BitPacked(); }else if (currentPixel != ' ') { currentColor = main; } } bi.setPixel(i, row, Colour.fromARGB32BitPacked(currentColor)); } row++; } _image = bi; return true; } @Override protected Picture createPicture() { return new FrameBitmap((Text) _source.copy(), _image); } @Override protected String getTagText() { return "@b: "; } }