File: GenericEmbosser.java

package info (click to toggle)
brailleutils 1.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 4,084 kB
  • sloc: java: 13,138; xml: 659; makefile: 29; sh: 1
file content (159 lines) | stat: -rw-r--r-- 4,977 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Braille Utils (C) 2010-2011 Daisy Consortium 
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library 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 Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org_daisy;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.daisy.braille.embosser.AbstractEmbosser;
import org.daisy.braille.embosser.ConfigurableEmbosser;
import org.daisy.braille.embosser.EmbosserFeatures;
import org.daisy.braille.embosser.EmbosserTools;
import org.daisy.braille.embosser.EmbosserWriter;
import org.daisy.braille.embosser.FileToDeviceEmbosserWriter;
import org.daisy.braille.embosser.SimpleEmbosserProperties;
import org.daisy.braille.table.Table;
import org.daisy.braille.table.TableCatalog;
import org.daisy.braille.table.TableFilter;
import org.daisy.paper.PageFormat;
import org.daisy.paper.Paper;
import org.daisy.paper.PrintPage;
import org.daisy.printing.Device;

public class GenericEmbosser extends AbstractEmbosser {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5756220386304696977L;
	private final static TableFilter tableFilter;
	
	static {
		tableFilter = new TableFilter() {
			//jvm1.6@Override
			public boolean accept(Table object) {
				if (object!=null) {
					return true; 
				} else { return false; }
			}
		};
	}
	
	public GenericEmbosser(String name, String desc,  Enum<? extends Enum<?>> identifier) {
		super(name, desc, identifier);
		setFeature(EmbosserFeatures.CELL_WIDTH, 6);
		setFeature(EmbosserFeatures.CELL_HEIGHT, 10);
	}

	//jvm1.6@Override
	public boolean supportsPrintPage(PrintPage dim) {
		return true;
	}
	
	//jvm1.6@Override
	public boolean supportsPageFormat(PageFormat pageFormat) {
		return true;
	}
	
    //jvm1.6@Override
	public boolean supportsPaper(Paper paper) {
		return true;
	}

	//jvm1.6@Override
	public TableFilter getTableFilter() {
		return tableFilter;
	}
	
	//jvm1.6@Override
	public EmbosserWriter newEmbosserWriter(OutputStream os) {
		PrintPage pp = new PrintPage(getPageFormat());

		TableCatalog btb = TableCatalog.newInstance();
		Table tc = btb.get(setTable.getIdentifier());
		tc.setFeature("fallback", getFeature("fallback"));
		tc.setFeature("replacement", getFeature("replacement"));
		ConfigurableEmbosser.Builder b = new ConfigurableEmbosser.Builder(os, tc.newBrailleConverter());
		b.breaks((String)getFeature("breaks"));
        // b.padNewline(Padding.NONE);
		b.padNewline((String)getFeature("padNewline"));
		SimpleEmbosserProperties sep;
		if (getPageFormat()!=null) {
			sep = new SimpleEmbosserProperties(
					EmbosserTools.getWidth(pp, getCellWidth()), 
					EmbosserTools.getHeight(pp, getCellHeight())
					).supportsAligning(supportsAligning());
		} else {
			//using Integer.MAX_VALUE because SimpleEmbosserProperties/EmbosserWriterProperties
			//does not support null width/height
			sep = new SimpleEmbosserProperties(
					Integer.MAX_VALUE, 
					Integer.MAX_VALUE
					//cannot support aligning for an unspecified page format
					).supportsAligning(false);
		}
		b.embosserProperties(sep.supports8dot(supports8dot())
				.supportsDuplex(supportsDuplex()));
		return b.build();
	}

	//jvm1.6@Override
	public EmbosserWriter newEmbosserWriter(Device device) {
		try {
			File f = File.createTempFile(this.getClass().getCanonicalName(), ".tmp");
			f.deleteOnExit();
			EmbosserWriter ew = newEmbosserWriter(new FileOutputStream(f));
			return new FileToDeviceEmbosserWriter(ew, f, device);
		} catch (IOException e) {
			// do nothing, fail
		}
		throw new IllegalArgumentException("Embosser does not support this feature.");
	}

    public boolean supportsVolumes() {
        return false;
    }

    public boolean supports8dot() {
        return false;
    }

    public boolean supportsDuplex() {
        return true;
    }

    public boolean supportsAligning() {
    	//should this be true?
        return true;
    }

	public boolean supportsZFolding() {
		return false;
	}
	
	//jvm1.6@Override
	public boolean supportsPrintMode(PrintMode mode) {
		return PrintMode.REGULAR == mode;
	}
	//jvm1.6@Override
	public PrintPage getPrintPage(PageFormat pageFormat) {
		return new PrintPage(pageFormat);
	}

}