Package ca.cgjennings.layout
Class GenderAwareMarkupRenderer
- java.lang.Object
-
- ca.cgjennings.layout.MarkupRenderer
-
- ca.cgjennings.layout.GenderAwareMarkupRenderer
-
public class GenderAwareMarkupRenderer extends MarkupRenderer
This class overrides thehandleUnknownTag
method ofMarkupRenderer
to allow arbitrary tags that vary with the gender of some object.More generally, it allows tags of the form <left/right> which will generate either the left text or the right text depending on the "gender" the renderer has been set to.
To prevent confusion with closing tags, if no text should be produced for a given gender, the tag should indicate this with a hyphen, e.g., <-/something> would produce either "" or "something".
Some examples of how the tags can be used:
-
<Jack/Diane> was a great scholar of old.
-
The priest<-/ess> is angry.
-
You bite <his/her/its/their> hand<-/-/-/s>.
-
The <orange/yellow/red/green> key fits this lock.
- Author:
- Chris Jennings
-
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ca.cgjennings.layout.MarkupRenderer
MarkupRenderer.StyledParagraph
-
-
Field Summary
Fields Modifier and Type Field Description static int
GENDER_LEFT
static int
GENDER_MIDDLE
static int
GENDER_RIGHT
-
Fields inherited from class ca.cgjennings.layout.MarkupRenderer
currentAutoclose, currentHeadlineStatus, currentIndex, currentJustification, currentParametricTag, currentPositionInUntaggedText, currentPunctuationReplacement, currentSourceLine, currentTag, currentTagEndingIndex, currentTagNoCase, currentTagStartingIndex, currentTightness, currentVerticalJustification, DEBUG, finishedStyles, FIT_BOTH, FIT_NONE, FIT_SCALE_TEXT, FIT_TIGHTEN_LINE_SPACING, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_JUSTIFY, LAYOUT_LEFT, LAYOUT_MIDDLE, LAYOUT_RIGHT, LAYOUT_TOP, openQuotes, styleStackMap, textHasWhitespace, USE_FAST_LINE_BREAKER, USE_PATCHED_LINE_BREAKER
-
-
Constructor Summary
Constructors Constructor Description GenderAwareMarkupRenderer()
GenderAwareMarkupRenderer(double dpi)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
capitalize(java.lang.String s)
Returns a string identical tos
except that the first character, if any and if it has a capital version, is capitalized.int
getGender()
Return the current gender setting as aboolean
;true
indicates that the right side of gender-sensitive tags will be selected.protected java.lang.String
handleUnknownTag(java.lang.String tagnameLowercase, java.lang.String tagnameOriginalCase)
Checks for tags of the form <m/f> or <capital m/f>and returns replacement text based on the current gender setting.void
setGender(boolean female)
Sets the "gender" using a simple male/female rule.void
setGender(int segmentToUse)
Set the segment of gender tags to be used.-
Methods inherited from class ca.cgjennings.layout.MarkupRenderer
addLibrary, adjustStyleForContext, appendSegments, breakIntoParagraphs, convertTagsToLinebreaks, createDefaultParametricStyleMap, createDefaultReplacementMap, createDefaultStyleMap, createStyledParagraph, createStyledText, draw, drawAsSingleLine, findReplacementForTag, getAlignment, getAutoclose, getBaseFile, getDefaultExpansionLimit, getDefaultStyle, getEvaluatorFactory, getExpansionLimit, getHeadlineAlignment, getLineTightness, getMarkBadBox, getMarkupText, getPageShape, getParametricStyleForTag, getReplacementForTag, getScalingFractionalLimit, getScalingLimit, getStyledText, getStyleForTag, getTabWidth, getTabWidths, getTagParameters, getTextFitting, getTightnessLimit, invalidateLayoutCache, layout, measure, parseLibrary, parseMeasurement, removeAllTags, removeTag, renderText, replaceMacroParameters, replaceTagWith, replaceTagWithErrorMessage, resetPunctuationSelectorState, selectPunctuation, setAlignment, setAutoclose, setBaseFile, setDefaultExpansionLimit, setDefaultStyle, setDefinitionForTag, setEvaluatorFactory, setExpansionLimit, setHeadlineAlignment, setLineTightness, setMarkBadBox, setMarkupText, setPageShape, setParametricStyleForTag, setReplacementForTag, setScalingFractionalLimit, setScalingLimit, setStyleForTag, setTabWidth, setTabWidths, setTextFitting, setTightnessLimit, toString
-
-
-
-
Field Detail
-
GENDER_LEFT
public static final int GENDER_LEFT
- See Also:
- Constant Field Values
-
GENDER_MIDDLE
public static final int GENDER_MIDDLE
- See Also:
- Constant Field Values
-
GENDER_RIGHT
public static final int GENDER_RIGHT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setGender
public void setGender(boolean female)
Sets the "gender" using a simple male/female rule. If female istrue
, the second segment of a gender tag is used. Iffalse
, the first segment is used.- Parameters:
female
- if the second segment should be used
-
setGender
public void setGender(int segmentToUse)
Set the segment of gender tags to be used. A gender tag may have any number of segments/separated/by/slashes. This index indicates which segment to use. A common mapping is 0 = male, 1 = female, 2 = plural ("they"), and 3 = neuter ("it").
-
getGender
public int getGender()
Return the current gender setting as aboolean
;true
indicates that the right side of gender-sensitive tags will be selected.
-
handleUnknownTag
protected java.lang.String handleUnknownTag(java.lang.String tagnameLowercase, java.lang.String tagnameOriginalCase)
Checks for tags of the form <m/f> or <capital m/f>and returns replacement text based on the current gender setting.- Overrides:
handleUnknownTag
in classMarkupRenderer
-
capitalize
public static java.lang.String capitalize(java.lang.String s)
Returns a string identical tos
except that the first character, if any and if it has a capital version, is capitalized.
-
-