~ubuntu-branches/ubuntu/raring/brailleutils/raring

« back to all changes in this revision

Viewing changes to catalog/com_braillo/AbstractBraillo440Embosser.java

  • Committer: Package Import Robot
  • Author(s): Sebastian Humenda
  • Date: 2011-08-27 12:21:13 UTC
  • Revision ID: package-import@ubuntu.com-20110827122113-72udcdbhzrqtdlgx
Tags: upstream-1.2~b
ImportĀ upstreamĀ versionĀ 1.2~b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Braille Utils (C) 2010-2011 Daisy Consortium 
 
3
 * 
 
4
 * This library is free software; you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Lesser General Public License as published by the Free
 
6
 * Software Foundation; either version 2.1 of the License, or (at your option)
 
7
 * any later version.
 
8
 * 
 
9
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
11
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 
12
 * details.
 
13
 * 
 
14
 * You should have received a copy of the GNU Lesser General Public License
 
15
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 
16
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
17
 */
 
18
package com_braillo;
 
19
 
 
20
import java.io.OutputStream;
 
21
 
 
22
import org.daisy.braille.embosser.BufferedVolumeEmbosser;
 
23
import org.daisy.braille.embosser.EmbosserFactoryException;
 
24
import org.daisy.braille.embosser.EmbosserTools;
 
25
import org.daisy.braille.embosser.EmbosserWriter;
 
26
import org.daisy.braille.embosser.SimpleEmbosserProperties;
 
27
import org.daisy.braille.embosser.StandardLineBreaks;
 
28
import org.daisy.braille.table.Table;
 
29
import org.daisy.braille.table.TableCatalog;
 
30
import org.daisy.paper.Area;
 
31
import org.daisy.paper.PageFormat;
 
32
import org.daisy.paper.PrintPage;
 
33
import org.daisy.paper.PrintPage.PrintDirection;
 
34
import org.daisy.printing.Device;
 
35
 
 
36
import com_braillo.Braillo440VolumeWriter.Mode;
 
37
import com_braillo.BrailloEmbosserProvider.EmbosserType;
 
38
 
 
39
public abstract class AbstractBraillo440Embosser extends BrailloEmbosser {
 
40
        /**
 
41
         * 
 
42
         */
 
43
        private static final long serialVersionUID = 3735464395595074473L;
 
44
        private final static double cellWidth = 19*EmbosserTools.INCH_IN_MM/80d; //6;
 
45
        private final static double cellHeight = 10;
 
46
        private final static double constant = 11*EmbosserTools.INCH_IN_MM/80d;
 
47
        
 
48
        protected boolean saddleStitchEnabled;
 
49
 
 
50
        public AbstractBraillo440Embosser(String name, String desc, Enum<? extends Enum<?>> identifier) {
 
51
                super(name, desc, identifier);
 
52
                saddleStitchEnabled = false;
 
53
                setCellWidth(cellWidth);
 
54
        }
 
55
 
 
56
        //jvm1.6@Override
 
57
        public boolean supportsPrintPage(PrintPage dim) {
 
58
                int width = (int)Math.floor((dim.getWidth()+constant-EmbosserTools.INCH_IN_MM) / cellWidth);
 
59
                int inchHeight = (int)Math.ceil(dim.getHeight()/EmbosserTools.INCH_IN_MM);
 
60
                if (width > 44 || inchHeight > 13 || width < 10) { 
 
61
                        return false; 
 
62
                }
 
63
                return true;
 
64
        }
 
65
 
 
66
        //jvm1.6@Override
 
67
        public EmbosserWriter newEmbosserWriter(OutputStream os) {
 
68
                throw  new IllegalArgumentException(new EmbosserFactoryException(getDisplayName() + " does not support writing to file."));
 
69
        }
 
70
 
 
71
        //jvm1.6@Override
 
72
        public EmbosserWriter newEmbosserWriter(Device device) {
 
73
                TableCatalog btb = TableCatalog.newInstance();
 
74
                Table tc = btb.get(setTable.getIdentifier());
 
75
                tc.setFeature("fallback", getFeature("fallback"));
 
76
                tc.setFeature("replacement", getFeature("replacement"));
 
77
                Braillo440VolumeWriter bvw;
 
78
                EmbosserType t = EmbosserType.valueOf(getIdentifier().substring(1+getIdentifier().lastIndexOf('.')));
 
79
                PrintPage printPage = getPrintPage(getPageFormat());
 
80
                int width = (int)Math.floor((printPage.getWidth()+constant-EmbosserTools.INCH_IN_MM) / cellWidth);
 
81
                int height = EmbosserTools.getHeight(printPage, cellHeight);
 
82
                double columnWidthMM = width * cellWidth - constant;
 
83
                if (t==EmbosserType.BRAILLO_440_SW && saddleStitchEnabled) {
 
84
                        bvw = new Braillo440VolumeWriter(printPage, Mode.SW_FOUR_PAGE, width, height, columnWidthMM);
 
85
                } else if (t==EmbosserType.BRAILLO_440_SW) {
 
86
                        bvw = new Braillo440VolumeWriter(printPage, Mode.SW_TWO_PAGE, width, height, columnWidthMM);
 
87
                } else if (t==EmbosserType.BRAILLO_440_SWSF) {
 
88
                        bvw = new Braillo440VolumeWriter(printPage, Mode.SWSF, width, height, columnWidthMM);
 
89
                } else {
 
90
                        throw new RuntimeException("Unexpected error.");
 
91
                }
 
92
                /*
 
93
                 *      public boolean supports8dot() {return false;}
 
94
 
 
95
        public boolean supportsAligning() {     return true;}
 
96
 
 
97
        public boolean supportsDuplex() {return true;}
 
98
 
 
99
        public int getMaxHeight() {return height; }
 
100
                public int getMaxWidth() {      return width;}
 
101
                 */
 
102
                SimpleEmbosserProperties ep = new SimpleEmbosserProperties(width, height)
 
103
                        .supports8dot(false)
 
104
                        .supportsAligning(true)
 
105
                        .supportsDuplex(true);
 
106
                BufferedVolumeEmbosser.Builder b = new BufferedVolumeEmbosser.Builder(device, tc.newBrailleConverter(), bvw, ep)
 
107
                        .breaks(new StandardLineBreaks(StandardLineBreaks.Type.DOS))
 
108
                        .padNewline(BufferedVolumeEmbosser.Padding.NONE) // JH100408: changed from BEFORE
 
109
                        .autoLineFeedOnEmptyPage(true);
 
110
                return b.build();
 
111
        }
 
112
        /*
 
113
        public int getMaxWidth(Paper paper) {
 
114
                return (int)Math.floor((paper.getWidth()+constant-EmbosserTools.INCH_IN_MM) / getCellWidth());
 
115
        }*/
 
116
 
 
117
    public boolean supports8dot() {
 
118
        return false;
 
119
    }
 
120
 
 
121
    public boolean supportsDuplex() {
 
122
        return true;
 
123
    }
 
124
 
 
125
    public boolean supportsAligning() {
 
126
        return true;
 
127
    }
 
128
 
 
129
    public boolean supportsVolumes() {
 
130
        return true;
 
131
    }
 
132
 
 
133
        public PrintPage getPrintPage(PageFormat pageFormat) {
 
134
                return new PrintPage(pageFormat,
 
135
                                PrintDirection.SIDEWAYS,
 
136
                                (saddleStitchEnabled?PrintMode.MAGAZINE:PrintMode.REGULAR)
 
137
                        );
 
138
        }
 
139
 
 
140
        public Area getPrintableArea(PageFormat pageFormat) {
 
141
                PrintPage printPage = getPrintPage(pageFormat);
 
142
                return new Area(printPage.getWidth(), printPage.getHeight(), 0, 0);
 
143
        }
 
144
 
 
145
        public boolean supportsZFolding() {
 
146
                return false;
 
147
        }
 
148
 
 
149
}