~ubuntu-branches/ubuntu/trusty/brailleutils/trusty

« back to all changes in this revision

Viewing changes to catalog/com_indexbraille/IndexV4Embosser.java

  • Committer: Package Import Robot
  • Author(s): Sebastian Humenda, Sebastian Humenda, Samuel Thibault
  • Date: 2013-04-11 18:45:11 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130411184511-gt0ygyia3i50nqap
Tags: 1.2.1-1
[ Sebastian Humenda ]
* updated to upstream v1.2.1
* separate front end for brailleutils (available as command with the same
  name)
* wrote man page for brailleUtils
* improved debian packaging: moved installation from debian/rules to
  *.install, *.dirs

[ Samuel Thibault ]
* control: Add missing junit4 dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import org.daisy.braille.embosser.ConfigurableEmbosser;
23
23
import org.daisy.braille.embosser.EmbosserFactoryException;
24
 
import org.daisy.braille.embosser.EmbosserTools;
25
24
import org.daisy.braille.embosser.EmbosserWriter;
26
25
import org.daisy.braille.embosser.EmbosserWriterProperties;
27
26
import org.daisy.braille.embosser.SimpleEmbosserProperties;
46
45
    private final static String table6dot = "org.daisy.braille.table.DefaultTableProvider.TableType.EN_US";
47
46
  //private final static String table8dot = "com_indexbraille.IndexTableProvider.TableType.INDEX_TRANSPARENT_8DOT";
48
47
 
 
48
    private int bindingMargin = 0;
 
49
    private static final int maxBindingMargin = 10;
 
50
 
49
51
    static {
50
52
        tableFilter = new TableFilter() {
51
53
            //jvm1.6@Override
64
66
        super(name, desc, identifier);
65
67
 
66
68
        setTable = TableCatalog.newInstance().get(table6dot);
 
69
        duplexEnabled = true;
67
70
 
68
71
        switch (type) {
69
72
            case INDEX_BASIC_D_V4:
 
73
                maxCellsInWidth = 49;
 
74
                break;
70
75
            case INDEX_EVEREST_D_V4:
71
 
                duplexEnabled = true;
 
76
            case INDEX_BRAILLE_BOX_V4:          
 
77
                maxCellsInWidth = 48;                
72
78
                break;
73
79
            default:
74
80
                throw new IllegalArgumentException("Unsupported embosser type");
75
81
        }
76
82
 
77
83
        maxNumberOfCopies = 10000;
78
 
        maxCellsInWidth = 42;
79
84
        maxMarginInner = 10;
80
85
        maxMarginOuter = 10;
81
86
        maxMarginTop = 10;
85
90
        return tableFilter;
86
91
    }
87
92
 
 
93
    @Override
 
94
    public boolean supportsPrintPage(PrintPage dim) {
 
95
 
 
96
        if (dim==null) { return false; }
 
97
        if (type == EmbosserType.INDEX_BRAILLE_BOX_V4) {
 
98
            Length across = dim.getLengthAcrossFeed();
 
99
            Length along = dim.getLengthAlongFeed();
 
100
            if (saddleStitchEnabled) {
 
101
                return (across.asMillimeter() == 297 && along.asMillimeter() == 420) ||
 
102
                       (across.asInches()     == 11  && along.asInches()     == 17);
 
103
            } else {
 
104
                return (across.asMillimeter() == 297 && along.asMillimeter() == 210) ||
 
105
                       (across.asInches()     == 11  && along.asInches()     == 8.5) ||
 
106
                       (across.asInches()     == 11  && along.asInches()     == 11.5);
 
107
            }
 
108
        } else {
 
109
            return super.supportsPrintPage(dim);
 
110
        }
 
111
    }
 
112
 
88
113
    public EmbosserWriter newEmbosserWriter(OutputStream os) {
89
114
 
90
115
        PageFormat page = getPageFormat();
101
126
            throw new IllegalArgumentException(new EmbosserFactoryException("Invalid number of copies: " + numberOfCopies + " is not in [1, 10000]"));
102
127
        }
103
128
 
104
 
        byte[] header = getIndexV3Header(eightDotsEnabled, duplexEnabled, cellsInWidth);
 
129
        byte[] header = getIndexV4Header();
105
130
        byte[] footer = new byte[0];
106
131
 
107
132
        EmbosserWriterProperties props =
127
152
        }
128
153
    }
129
154
 
130
 
    private byte[] getIndexV3Header(boolean eightDots,
131
 
                                    boolean duplex,
132
 
                                    int cellsInWidth) {
133
 
 
134
 
        PrintPage page = getPrintPage(getPageFormat());
135
 
        Length length = page.getLengthAlongFeed();
136
 
        Length width = page.getLengthAcrossFeed();
137
 
 
138
 
        byte[] xx;
139
 
        byte y;
140
 
        double iPart;
141
 
        double fPart;
 
155
    private byte[] getIndexV4Header() {
142
156
 
143
157
        StringBuffer header = new StringBuffer();
144
158
 
145
159
        header.append((char)0x1b);
146
 
        header.append("D");                                         // Activate temporary formatting properties of a document
147
 
        header.append("BT0");                                       // Default braille table
148
 
        header.append(",TD0");                                      // Text dot distance = 2.5 mm
149
 
        header.append(",LS50");                                     // Line spacing = 5 mm
 
160
        header.append("D");                                           // Activate temporary formatting properties of a document
 
161
        header.append("BT0");                                         // Default braille table
 
162
        header.append(",TD0");                                        // Text dot distance = 2.5 mm
 
163
        header.append(",LS50");                                       // Line spacing = 5 mm
150
164
        header.append(",DP");
151
 
        if (saddleStitchEnabled)       { header.append('4'); } else
152
 
        if (zFoldingEnabled && duplex) { header.append('3'); } else
153
 
        if (zFoldingEnabled)           { header.append('5'); } else
154
 
        if (duplex)                    { header.append('2'); } else
155
 
                                       { header.append('1'); }      // Page mode
 
165
 
 
166
        if (saddleStitchEnabled
 
167
                && !duplexEnabled)   { header.append('8'); } else
 
168
//      if (swZFoldingEnabled
 
169
//              && !duplexEnabled)   { header.append('7'); } else
 
170
//      if (swZFoldingEnabled)       { header.append('6'); } else
 
171
        if (zFoldingEnabled
 
172
                && !duplexEnabled)   { header.append('5'); } else
 
173
        if (saddleStitchEnabled)     { header.append('4'); } else
 
174
        if (zFoldingEnabled)         { header.append('3'); } else
 
175
        if (duplexEnabled)           { header.append('2'); } else
 
176
                                     { header.append('1'); }          // Page mode
156
177
        if (numberOfCopies > 1) {
157
178
            header.append(",MC");
158
 
            header.append(String.valueOf(numberOfCopies));          // Multiple copies
159
 
        }
160
 
        //header.append(",MI1");                                    // Multiple impact = 1
161
 
        header.append(",PN0");                                      // No page number
162
 
        switch (type) {
163
 
            case INDEX_BASIC_D_V4: {
164
 
                iPart = Math.floor(length.asInches());
165
 
                fPart = (length.asInches() - iPart);
166
 
                                     xx = EmbosserTools.toBytes((int)iPart, 2);
167
 
                if (fPart > 0.75)  { xx = EmbosserTools.toBytes((int)(iPart + 1), 2);
168
 
                                     y = '0'; } else
169
 
                if (fPart > 2d/3d) { y = '5'; } else
170
 
                if (fPart > 0.5)   { y = '4'; } else
171
 
                if (fPart > 1d/3d) { y = '3'; } else
172
 
                if (fPart > 0.25)  { y = '2'; } else
173
 
                if (fPart > 0)     { y = '1'; } else
174
 
                                   { y = '0'; }
175
 
                header.append(",PL");
176
 
                header.append((char)xx[0]);
177
 
                header.append((char)xx[1]);
178
 
                header.append((char)y);                             // Paper length
179
 
 
180
 
                iPart = Math.floor(width.asInches());
181
 
                fPart = (width.asInches() - iPart);
182
 
                                     xx = EmbosserTools.toBytes((int)iPart, 2);
183
 
                if (fPart > 0.75)  { xx = EmbosserTools.toBytes((int)(iPart + 1), 2);
184
 
                                     y = '0'; } else
185
 
                if (fPart > 2d/3d) { y = '5'; } else
186
 
                if (fPart > 0.5)   { y = '4'; } else
187
 
                if (fPart > 1d/3d) { y = '3'; } else
188
 
                if (fPart > 0.25)  { y = '2'; } else
189
 
                if (fPart > 0)     { y = '1'; } else
190
 
                                   { y = '0'; }
191
 
                header.append(",PW");
192
 
                header.append((char)xx[0]);
193
 
                header.append((char)xx[1]);
194
 
                header.append((char)y);                             // Paper width
195
 
                break;
196
 
            }
197
 
            case INDEX_EVEREST_D_V4: {
198
 
                header.append(",PL");
199
 
                header.append(String.valueOf(
200
 
                    (int)Math.ceil(length.asMillimeter())));        // Paper length
201
 
                header.append(",PW");
202
 
                header.append(String.valueOf(
203
 
                    (int)Math.ceil(width.asMillimeter())));         // Paper width
204
 
                break;
205
 
            }
206
 
            default:
207
 
        }
 
179
            header.append(String.valueOf(numberOfCopies));            // Multiple copies
 
180
        }
 
181
        //header.append(",MI1");                                      // Multiple impact = 1
 
182
        header.append(",PN0");                                        // No page number
208
183
        header.append(",CH");
209
 
        header.append(String.valueOf(cellsInWidth));                // Characters per line
210
 
        header.append(",IM");
211
 
        header.append(String.valueOf(marginInner));                 // Inner margin
212
 
        header.append(",OM");
213
 
        header.append(String.valueOf(marginOuter));                 // Outer margin
 
184
        header.append(String.valueOf(getMaxWidth(getPageFormat())));  // Characters per line
 
185
        header.append(",LP");
 
186
        header.append(String.valueOf(getMaxHeight(getPageFormat()))); // Lines per page
 
187
        header.append(",BI");
 
188
        header.append(String.valueOf(bindingMargin));                 // Binding margin
214
189
        header.append(",TM");
215
 
        header.append(String.valueOf(marginTop));                   // Top margin
216
 
        header.append(",BM");
217
 
        header.append(String.valueOf(marginBottom));                // Bottom margin
 
190
        header.append(String.valueOf(marginTop));                     // Top margin
 
191
 
218
192
        header.append(";");
219
193
 
220
194
        return header.toString().getBytes();