Class AbstractEmbosserWriter
- java.lang.Object
-
- org.daisy.braille.utils.impl.tools.embosser.AbstractEmbosserWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,EmbosserWriter
,EmbosserWriterProperties
- Direct Known Subclasses:
BufferedVolumeEmbosser
,ConfigurableEmbosser
,IndexTransparentEmbosserWriter
,MicroBrailleFileFormatWriter
public abstract class AbstractEmbosserWriter extends Object implements EmbosserWriter
Provides an abstract base for embossers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractEmbosserWriter.Padding
Defines form feed padding style.
-
Field Summary
Fields Modifier and Type Field Description protected PageBreaks
pagebreaks
protected InternalEmbosserWriterProperties
props
-
Constructor Summary
Constructors Constructor Description AbstractEmbosserWriter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addAll(byte[] b)
Adds bytes to the EmbosserWriter output.void
close()
int
currentPage()
Gets the current page number, where the first page is 1.protected void
formFeed()
Performs a form feed on the EmbosserWriter.abstract byte[]
getBytes(String braille)
Translates a string of braille into bytes that should be transfered to the embosser.abstract LineBreaks
getLinebreakStyle()
Gets the line break style for the EmbosserWriter.int
getMaxWidth()
Gets the maximum row width in the current configuration.abstract AbstractEmbosserWriter.Padding
getPaddingStyle()
Gets the form feed padding style for the EmbosserWriter.protected PageBreaks
getPagebreakStyle()
int
getRowGap()
Gets the current row gap, measured as an integer multiple of the dot-to-dot height.protected void
init(InternalEmbosserWriterProperties props)
boolean
isClosed()
Tests if embosser has been closed.boolean
isOpen()
Returns true if embosser is open.protected void
lineFeed()
Performs a line feed on the EmbosserWriter.void
newLine()
Starts a new line.void
newPage()
Starts a new page.void
newSectionAndPage(boolean duplex)
Starts a new page on a blank sheet of paper with the specified duplex settings.void
newVolumeSectionAndPage(boolean duplex)
Starts a new page on a blank sheet of paper in a new volume with the specified duplex settings.void
open(boolean duplex)
Opens for writing using the default contract.boolean
pageIsEmpty()
Returns true if page is empty.void
setRowGap(int value)
Sets the row gap for following calls to newLine to the specified value, measured as an integer multiple of the dot-to-dot height.boolean
supportsAligning()
Returns true if this embosser supports aligning.void
write(String braille)
Writes a string of braille to the embosser.
-
-
-
Field Detail
-
props
protected InternalEmbosserWriterProperties props
-
pagebreaks
protected PageBreaks pagebreaks
-
-
Method Detail
-
getLinebreakStyle
public abstract LineBreaks getLinebreakStyle()
Gets the line break style for the EmbosserWriter.- Returns:
- returns the line break style for the EmbosserWriter
-
getPaddingStyle
public abstract AbstractEmbosserWriter.Padding getPaddingStyle()
Gets the form feed padding style for the EmbosserWriter.- Returns:
- returns the padding style for the EmbosserWriter
-
addAll
protected abstract void addAll(byte[] b) throws IOException
Adds bytes to the EmbosserWriter output.- Parameters:
b
- the bytes to add- Throws:
IOException
- if IO fails
-
init
protected void init(InternalEmbosserWriterProperties props)
-
newLine
public void newLine() throws IOException
Description copied from interface:EmbosserWriter
Starts a new line.- Specified by:
newLine
in interfaceEmbosserWriter
- Throws:
IOException
- if an I/O error occurs
-
setRowGap
public void setRowGap(int value)
Description copied from interface:EmbosserWriter
Sets the row gap for following calls to newLine to the specified value, measured as an integer multiple of the dot-to-dot height.- Specified by:
setRowGap
in interfaceEmbosserWriter
- Parameters:
value
- the row gap
-
getRowGap
public int getRowGap()
Description copied from interface:EmbosserWriter
Gets the current row gap, measured as an integer multiple of the dot-to-dot height.- Specified by:
getRowGap
in interfaceEmbosserWriter
- Returns:
- returns the current row gap
-
open
public void open(boolean duplex) throws IOException
Description copied from interface:EmbosserWriter
Opens for writing using the default contract.- Specified by:
open
in interfaceEmbosserWriter
- Parameters:
duplex
- true if both sides of sheets should be used, false otherwise- Throws:
IOException
- if an I/O error occurs
-
currentPage
public int currentPage()
Gets the current page number, where the first page is 1.- Returns:
- returns the current page number
-
pageIsEmpty
public boolean pageIsEmpty()
Returns true if page is empty.- Returns:
- returns true if page is empty
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
write
public void write(String braille) throws IOException
Description copied from interface:EmbosserWriter
Writes a string of braille to the embosser. Values must be between 0x2800 and 0x28FF. An implementation may supply a complete row of braille in a single chunk. However, an implementation may also call this method repeatedly without any other calls in between.- Specified by:
write
in interfaceEmbosserWriter
- Parameters:
braille
- characters in the range 0x2800 to 0x28FF- Throws:
IOException
- if an I/O error occurs
-
getBytes
public abstract byte[] getBytes(String braille) throws UnsupportedEncodingException
Translates a string of braille into bytes that should be transfered to the embosser.- Parameters:
braille
- the braille (characters in the Braille Patterns unicode block 0x2800-0x28FF).- Returns:
- the bytes
- Throws:
UnsupportedEncodingException
- if the string could not be encoded.
-
lineFeed
protected void lineFeed() throws IOException
Performs a line feed on the EmbosserWriter.- Throws:
IOException
- if IO fails
-
formFeed
protected void formFeed() throws IOException
Performs a form feed on the EmbosserWriter.- Throws:
IOException
- if IO fails
-
getPagebreakStyle
protected PageBreaks getPagebreakStyle()
-
newPage
public void newPage() throws IOException
Description copied from interface:EmbosserWriter
Starts a new page.- Specified by:
newPage
in interfaceEmbosserWriter
- Throws:
IOException
- if an I/O error occurs
-
newSectionAndPage
public void newSectionAndPage(boolean duplex) throws IOException
Description copied from interface:EmbosserWriter
Starts a new page on a blank sheet of paper with the specified duplex settings.- Specified by:
newSectionAndPage
in interfaceEmbosserWriter
- Parameters:
duplex
- if both sides of sheets should be used, false otherwise- Throws:
IOException
- if an I/O error occurs
-
newVolumeSectionAndPage
public void newVolumeSectionAndPage(boolean duplex) throws IOException
Description copied from interface:EmbosserWriter
Starts a new page on a blank sheet of paper in a new volume with the specified duplex settings.- Specified by:
newVolumeSectionAndPage
in interfaceEmbosserWriter
- Parameters:
duplex
- if both sides of sheets should be used, false otherwise- Throws:
IOException
- if an I/O error occurs
-
isOpen
public boolean isOpen()
Description copied from interface:EmbosserWriter
Returns true if embosser is open.- Specified by:
isOpen
in interfaceEmbosserWriter
- Returns:
- returns true if embosser is open, false otherwise
-
isClosed
public boolean isClosed()
Description copied from interface:EmbosserWriter
Tests if embosser has been closed.- Specified by:
isClosed
in interfaceEmbosserWriter
- Returns:
- returns true if the embosser has been open, but is now closed, false otherwise
-
getMaxWidth
public int getMaxWidth()
Description copied from interface:EmbosserWriterProperties
Gets the maximum row width in the current configuration.- Specified by:
getMaxWidth
in interfaceEmbosserWriterProperties
- Returns:
- returns the maximum row width, in characters
-
supportsAligning
public boolean supportsAligning()
Description copied from interface:EmbosserWriterProperties
Returns true if this embosser supports aligning. This indicates that rows can be padded with whitespace to move the text block horizontally using the value returned bygetMaxWidth
. Should return true for all physical embossers, since they all have a finite row length.- Specified by:
supportsAligning
in interfaceEmbosserWriterProperties
- Returns:
- returns true if this embosser supports aligning, false otherwise.
-
-