File: MicroBrailleFileFormatWriter.java

package info (click to toggle)
brailleutils 1.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,084 kB
  • sloc: java: 13,138; xml: 659; makefile: 29; sh: 1
file content (125 lines) | stat: -rw-r--r-- 3,787 bytes parent folder | download | duplicates (5)
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
/*
 * 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.IOException;
import java.io.OutputStream;

import org.daisy.braille.embosser.AbstractEmbosserWriter;
import org.daisy.braille.embosser.LineBreaks;
import org.daisy.braille.embosser.SimpleEmbosserProperties;
import org.daisy.braille.embosser.StandardLineBreaks;
import org.daisy.braille.table.BrailleConverter;
import org_daisy.BrailleEditorsTableProvider.TableType;

/**
 *
 * @author  Bert Frees
 */
public class MicroBrailleFileFormatWriter extends AbstractEmbosserWriter {

    private OutputStream os = null;
    private BrailleConverter table = null;
    private LineBreaks breaks;
    private Padding padding;
    private byte[] header;

    
    public MicroBrailleFileFormatWriter(OutputStream os) {

        int cols = 25; // ??? examine PEF file => Contract?
        int rows = 40; // ??? examine PEF file

        this.os = os;
        header = ("$" + rows).getBytes();
        breaks = new StandardLineBreaks(StandardLineBreaks.Type.DOS);
        pagebreaks = new NoPageBreaks();
        padding = Padding.AFTER;
        table = new BrailleEditorsTableProvider().newTable(TableType.MICROBRAILLE);

        SimpleEmbosserProperties props = new SimpleEmbosserProperties(cols, rows)
                       .supportsDuplex(false)
                       .supports8dot(false)
                       .supportsVolumes(false)
                       .supportsAligning(false);
        init(props);
    }

    //jvm1.6@Override
    public LineBreaks getLinebreakStyle() {
        return breaks;
    }

    //jvm1.6@Override
    public Padding getPaddingStyle() {
        return padding;
    }

    //jvm1.6@Override
    public BrailleConverter getTable() {
        return table;
    }

    //jvm1.6@Override
    protected void add(byte b) throws IOException {
        os.write(b);
    }

    //jvm1.6@Override
    protected void addAll(byte[] bytes) throws IOException {
        os.write(bytes);
    }

    @Override
    protected void formFeed() throws IOException {
        super.formFeed();
        if (currentPage()==1) {
            byte[] pageBreak = "----|---|---------------------------|+-".getBytes();
            if (getMaxWidth()<40) {
                pageBreak[getMaxWidth()-1] = '>';
            }
            addAll(pageBreak);
        }
        addAll(getLinebreakStyle().getString().getBytes());
    }

    @Override
    public void open(boolean duplex)
              throws IOException {

        super.open(duplex);
        addAll(header);
        addAll(getLinebreakStyle().getString().getBytes());
    }

    @Override
    public void close() throws IOException {
        os.close();
        super.close();
    }

	public boolean supportsZFolding() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean supportsPrintMode(PrintMode mode) {
		return mode == PrintMode.REGULAR;
	}
}