org.foray.text.line
Class LineBreaker

java.lang.Object
  extended by org.foray.text.line.LineBreaker
All Implemented Interfaces:
org.axsl.text.line.LineBreaker
Direct Known Subclasses:
EagerLineBreaker, PatientLineBreaker

public abstract class LineBreaker
extends Object
implements org.axsl.text.line.LineBreaker

Abstract superclass for all line breakers.


Constructor Summary
protected LineBreaker(TextServer4a server, org.axsl.text.line.LineBreakControl control, org.axsl.text.line.LineBreakHandler handler, org.axsl.font.FontConsumer fontConsumer)
          Constructor.
 
Method Summary
static boolean allowsLineBreak(int codePoint)
          Determines whether a character allows (but does not force) a line break.
static boolean canBreakMidWord(String language)
          Indicates the validity of breaking a word in the middle without hyphenation, based on a given language.
protected  int charWidth(org.axsl.text.line.LineText lineText, int codePoint, int whitespaceWidth)
          Computes the width of a given character.
static boolean forcesLineBreak(int codePoint)
          Determines whether a character forces a line break.
 int getCharWidth(org.axsl.text.line.LineText lineText, int codePoint)
          Returns the width of a character.
protected  org.axsl.font.FontConsumer getFontConsumer()
          Returns the font consumer.
 org.axsl.text.line.LineBreakHandler getHandler()
          Returns the handler.
 int getHyphenWidth(org.axsl.text.line.LineText lineText)
          Returns the width of the hyphenation character.
 org.axsl.text.line.LineBreakControl getLineBreakControl()
          Return the LineBreakControl instance.
 org.apache.commons.logging.Log getLogger()
          Returns the logger.
 TextServer4a getTextServer()
          Return the text server.
 int getWordWidth(org.axsl.text.line.LineText lineText, CharSequence word, int offset, int length)
          Compute the width of a given word.
 boolean isInLowerCase()
          Indicates whether the current chunk of text is lower-case for purposes of faux small-caps or not.
 boolean isLowerCase(int codePoint)
          Indicates whether a given Unicode code point should be considered to be lower case.
static boolean isNonBreakingSpace(int codePoint)
          Determine if a given character is a non-breaking space.
static boolean isSpace(int codePoint)
          Helper method to determine if the character is a space with normal behavior.
 boolean isUpperCase(int codePoint)
          Indicates whether a given Unicode code point should be considered to be upper case.
static boolean isWhitespace(int codePoint)
          Indicates whether a given character should be considered whitespace.
static boolean isZeroWidthSpace(int codePoint)
          Indicates whether a given character is a zero-width space.
 void setInLowerCase(boolean inLowerCase)
          Sets the "in-lower-case" value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineBreaker

protected LineBreaker(TextServer4a server,
                      org.axsl.text.line.LineBreakControl control,
                      org.axsl.text.line.LineBreakHandler handler,
                      org.axsl.font.FontConsumer fontConsumer)
Constructor.

Parameters:
server - The "parent" TextServer.
control - The client object that provides process-time information, specifically by providing line length information.
handler - The client object that is responsible for taking the results of the line-breaking work and doing something with it.
fontConsumer - Provides the line-breaking system with the FontConsumer instance that should be used for interfacing with the Font subsystem.
Method Detail

getCharWidth

public int getCharWidth(org.axsl.text.line.LineText lineText,
                        int codePoint)
Returns the width of a character.

Parameters:
lineText - The object containing information about font and font size needed to get the width.
codePoint - The Unicode code point whose width is needed.
Returns:
The width of codePoint, in millipoints.

isLowerCase

public boolean isLowerCase(int codePoint)
Indicates whether a given Unicode code point should be considered to be lower case.

Parameters:
codePoint - The Unicode code point to be tested.
Returns:
True iff codePoint is lower case.

isUpperCase

public boolean isUpperCase(int codePoint)
Indicates whether a given Unicode code point should be considered to be upper case.

Parameters:
codePoint - The Unicode code point to be tested.
Returns:
True iff codePoint is upper case.

getHyphenWidth

public int getHyphenWidth(org.axsl.text.line.LineText lineText)
Returns the width of the hyphenation character.

Parameters:
lineText - The object containing information about font, font size, and hyphenation character needed to get the width.
Returns:
The width of the hyphenation character, in millipoints.

isSpace

public static boolean isSpace(int codePoint)
Helper method to determine if the character is a space with normal behavior. Normal behaviour means that it's not non-breaking, that is, that we are permitted to use it as a line-breaking opportunity.

Parameters:
codePoint - The Unicode code point to be tested.
Returns:
True iff codePoint is a normal space.

isNonBreakingSpace

public static boolean isNonBreakingSpace(int codePoint)
Determine if a given character is a non-breaking space.

Parameters:
codePoint - The Unicode code point to be tested.
Returns:
True iff codePoint is a non-breaking space.

forcesLineBreak

public static boolean forcesLineBreak(int codePoint)
Determines whether a character forces a line break.

Parameters:
codePoint - The character to be tested.
Returns:
True iff this character forces a line break.

allowsLineBreak

public static boolean allowsLineBreak(int codePoint)
Determines whether a character allows (but does not force) a line break.

Parameters:
codePoint - The character to be tested.
Returns:
True iff this character allows (but does not force) a line break.

isWhitespace

public static boolean isWhitespace(int codePoint)
Indicates whether a given character should be considered whitespace.

Parameters:
codePoint - The Unicode code point to be tested.
Returns:
True iff codePoint is whitespace.

isZeroWidthSpace

public static boolean isZeroWidthSpace(int codePoint)
Indicates whether a given character is a zero-width space.

Parameters:
codePoint - The Unicode code point to be tested.
Returns:
True iff codePoint is a zero-width space.

charWidth

protected int charWidth(org.axsl.text.line.LineText lineText,
                        int codePoint,
                        int whitespaceWidth)
Computes the width of a given character.

Parameters:
lineText - The object which knows the font and font size information for the text tested.
codePoint - The Unicode code point whose width is needed.
whitespaceWidth - The pre-computed whitespace width for this font.
Returns:
The computed width of the given code point.

getFontConsumer

protected org.axsl.font.FontConsumer getFontConsumer()
Returns the font consumer.

Returns:
The font consumer.

getLogger

public org.apache.commons.logging.Log getLogger()
Returns the logger.

Returns:
The logger.

canBreakMidWord

public static boolean canBreakMidWord(String language)
Indicates the validity of breaking a word in the middle without hyphenation, based on a given language. The CJKV languages allow this, since the ideographs are themselves distinct words or word-like concepts.

Parameters:
language - The language code to be tested.
Returns:
True iff it is legal to break a word in the middle

getTextServer

public TextServer4a getTextServer()
Return the text server.

Returns:
The text server.

getWordWidth

public int getWordWidth(org.axsl.text.line.LineText lineText,
                        CharSequence word,
                        int offset,
                        int length)
Compute the width of a given word.

Parameters:
lineText - The object providing font and font size information.
word - The word whose size is needed.
offset - The zero-based index into chars that is the start of what should be computed.
length - The number of chars in chars that should be computed.
Returns:
The width, in millipoints, of word.

isInLowerCase

public boolean isInLowerCase()
Indicates whether the current chunk of text is lower-case for purposes of faux small-caps or not.

Returns:
The "in-lower-case" value.

setInLowerCase

public void setInLowerCase(boolean inLowerCase)
Sets the "in-lower-case" value.

Parameters:
inLowerCase - Indicates whether the current chunk of text is lower-case for purposes of faux small-caps or not.

getHandler

public org.axsl.text.line.LineBreakHandler getHandler()
Returns the handler.

Returns:
The handler.

getLineBreakControl

public org.axsl.text.line.LineBreakControl getLineBreakControl()
Return the LineBreakControl instance.

Returns:
The line-break control.


Copyright © 2017. All rights reserved.