Class FreeTextAnnotation
-
- All Implemented Interfaces:
public class FreeTextAnnotation extends Annotation
Represents a free text annotation on the page. The annotation’s text color comes from the color property of Annotation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
FreeTextAnnotation.FreeTextAnnotationIntent
Possible styles of free text annotation.
public enum
FreeTextAnnotation.FreeTextTextJustification
Possible values for the alignment of the text.
-
Constructor Summary
Constructors Constructor Description FreeTextAnnotation(int pageIndex, RectF rect, String contents)
Creates a new FreeText annotation. FreeTextAnnotation(AnnotationPropertyManager properties, boolean markDirty)
Intended for internal usage only.
-
Method Summary
Modifier and Type Method Description AnnotationType
getType()
Gets the annotation type of the annotation. boolean
isResizable()
Check if the annotation is resizable, or if this is a non-resizable annotation. Size
getMinimumSize()
Returns the minimum size of the annotation. void
updateTransformationProperties(@NonNull() RectF newBoundingBox, @NonNull() RectF oldBoundingBox)
Annotations may override this method to transform their properties (i.e. FreeTextAnnotation.FreeTextAnnotationIntent
getIntent()
Returns type (also called intent) of the free text annotation. void
setIntent(@NonNull() FreeTextAnnotation.FreeTextAnnotationIntent intent)
Sets the type (also called intent) of the free text annotations. EdgeInsets
getTextInsets()
Gets the insets that are applied to the text. void
setTextInsets(@NonNull() EdgeInsets edgeInsets)
Sets the insets that are applied to the text. List<PointF>
getCallOutPoints()
Gets the points used to describe the call out line. void
setCallOutPoints(@NonNull() List<PointF> points)
Sets the call out points for this free text annotation. LineEndType
getLineEnd()
The line end for the call out line. void
setLineEnd(@NonNull() LineEndType lineEnd)
Sets the line end for the call out line. float
getTextSize()
Returns the text size set to this annotation. void
setTextSize(float textSize)
Sets the text size of this annotation. int
getTextStrokeColor()
Returns text stroke color of this annotation. void
setTextStrokeColor(@ColorInt() int color)
Sets the color of annotations text stroke. void
setTextJustification(@NonNull() FreeTextAnnotation.FreeTextTextJustification justification)
Sets the text justification to use. void
setVerticalTextAlignment(@NonNull() VerticalTextAlignment verticalAlignment)
Sets the vertical text alignment to use. FreeTextAnnotation.FreeTextTextJustification
getTextJustification()
Returns the text justification used by this free text annotation. VerticalTextAlignment
getVerticalTextAlignment()
Returns the vertical text alignment used by this free text annotation. int
getRotation()
Returns the clockwise rotation of this free text annotation in degrees. void
setRotation(int rotation, @NonNull() Size contentSize, boolean adjustBounds)
Sets the rotation of this free text annotation. void
setRotation(int rotation)
Sets the rotation of this free text annotation. void
adjustBoundsForRotation()
This adjusts the annotations bounding box to the smallest possible size that will encompass the rotated annotations at it's default size. void
setFontName(@Nullable() String fontName)
Sets the font name to be used by this FreeTextAnnotation. String
getFontName()
Gets the font name set for usage with this FreeTextAnnotation. boolean
isUiRotationSupported()
Returns true if this Annotation can be rotated in the UI. void
resizeToFitText(@NonNull() AnnotationConfigurationRegistry annotationConfigurationRegistry, @NonNull() Size pageSize)
Resizes the annotation to fit the text. void
setFlags(@NonNull() EnumSet<AnnotationFlags> flags)
Sets the annotation flags for this annotation. void
setContentSize(@Nullable() RectF contentSize, boolean adjustedForPageRotation)
Sets the inner bounds that are used when rotating the annotation. -
-
Constructor Detail
-
FreeTextAnnotation
FreeTextAnnotation(int pageIndex, RectF rect, String contents)
Creates a new FreeText annotation.- Parameters:
pageIndex
- Page to which this annotation will be attached to.rect
- Bounding rectangle for this annotation's text.contents
- Text of the annotation.
-
FreeTextAnnotation
FreeTextAnnotation(AnnotationPropertyManager properties, boolean markDirty)
Intended for internal usage only.
-
-
Method Detail
-
getType
@NonNull() AnnotationType getType()
Gets the annotation type of the annotation.
- Returns:
The type of the annotation. Makes down casting easier.
-
isResizable
boolean isResizable()
Check if the annotation is resizable, or if this is a non-resizable annotation.
- Returns:
true
if the annotation can be resized (e.g. ink annotation) orfalse
if it is a non-resizable one (e.g. note annotation).
-
getMinimumSize
@NonNull() Size getMinimumSize()
Returns the minimum size of the annotation.
- Returns:
The minimum annotation size in PDF points.
-
updateTransformationProperties
void updateTransformationProperties(@NonNull() RectF newBoundingBox, @NonNull() RectF oldBoundingBox)
Annotations may override this method to transform their properties (i.e. points, rects, sizes) whenever the bounding box of the annotation changed.
- Parameters:
newBoundingBox
- New bounding box of the annotation (in PDF points).oldBoundingBox
- Old bounding box of the annotation (in PDF points).
-
getIntent
@NonNull() FreeTextAnnotation.FreeTextAnnotationIntent getIntent()
Returns type (also called intent) of the free text annotation.
- Returns:
Value from .
-
setIntent
void setIntent(@NonNull() FreeTextAnnotation.FreeTextAnnotationIntent intent)
Sets the type (also called intent) of the free text annotations.
- Parameters:
intent
- One of FreeTextAnnotationIntent.
-
getTextInsets
@NonNull() EdgeInsets getTextInsets()
Gets the insets that are applied to the text. This describes the offset of the inner rect containing the text, to the bounding box.
- Returns:
The inset of the text rect to the bounds.
-
setTextInsets
void setTextInsets(@NonNull() EdgeInsets edgeInsets)
Sets the insets that are applied to the text.
- Parameters:
edgeInsets
- The amount to inset the text in the bounding box.
-
getCallOutPoints
@NonNull() List<PointF> getCallOutPoints()
Gets the points used to describe the call out line.
- Returns:
The points describing the call out line.
-
setCallOutPoints
void setCallOutPoints(@NonNull() List<PointF> points)
Sets the call out points for this free text annotation. This needs to be either 2 or 3 points, with the first point also having a line end.
- Parameters:
points
- The points for the call out line.
-
getLineEnd
@NonNull() LineEndType getLineEnd()
The line end for the call out line.
- Returns:
The line end for the call out line.
-
setLineEnd
void setLineEnd(@NonNull() LineEndType lineEnd)
Sets the line end for the call out line.
- Parameters:
lineEnd
- One of LineEndType.
-
getTextSize
float getTextSize()
Returns the text size set to this annotation.
- Returns:
Text size for this annotation (in PDF points).
-
setTextSize
void setTextSize(float textSize)
Sets the text size of this annotation.
- Parameters:
textSize
- Text size to be set (in PDF points).
-
getTextStrokeColor
@ColorInt() int getTextStrokeColor()
Returns text stroke color of this annotation. For the main text color use getColor.
- Returns:
Text stroke color of this annotations or
0
if no color was set.
-
setTextStrokeColor
void setTextStrokeColor(@ColorInt() int color)
Sets the color of annotations text stroke. For the main text color use setColor.
- Parameters:
color
- Text stroke color of this annotation or0
to clear the value.
-
setTextJustification
void setTextJustification(@NonNull() FreeTextAnnotation.FreeTextTextJustification justification)
Sets the text justification to use. One of FreeTextTextJustification.
- Parameters:
justification
- The justification to use for text of this annotation.
-
setVerticalTextAlignment
void setVerticalTextAlignment(@NonNull() VerticalTextAlignment verticalAlignment)
Sets the vertical text alignment to use. One of VerticalTextAlignment.
- Parameters:
verticalAlignment
- The vertical alignment to use for the text of this annotation.
-
getTextJustification
@NonNull() FreeTextAnnotation.FreeTextTextJustification getTextJustification()
Returns the text justification used by this free text annotation.
- Returns:
One of FreeTextTextJustification.
-
getVerticalTextAlignment
@NonNull() VerticalTextAlignment getVerticalTextAlignment()
Returns the vertical text alignment used by this free text annotation.
- Returns:
One of VerticalTextAlignment.
-
getRotation
int getRotation()
Returns the clockwise rotation of this free text annotation in degrees.
- Returns:
The clockwise rotation of this free text annotation in degrees.
-
setRotation
void setRotation(int rotation, @NonNull() Size contentSize, boolean adjustBounds)
Sets the rotation of this free text annotation.
See also adjustBoundsForRotation.
- Parameters:
rotation
- The clockwise rotation in degrees.contentSize
- The size of the annotation content, it will be rotated and scaled to fit inside the actual bounding box.adjustBounds
- Iftrue
will also adjust the bounding box to match the new rotation.
-
setRotation
void setRotation(int rotation)
Sets the rotation of this free text annotation. This will adjust the bounding box so rotating the annotation will cause the bounds to change.
- Parameters:
rotation
- The clockwise rotation in degrees.
-
adjustBoundsForRotation
void adjustBoundsForRotation()
This adjusts the annotations bounding box to the smallest possible size that will encompass the rotated annotations at it's default size.
-
setFontName
void setFontName(@Nullable() String fontName)
Sets the font name to be used by this FreeTextAnnotation.
- Parameters:
fontName
- The name of the font family to use, shouldn't include font weight e.g.
-
getFontName
@Nullable() String getFontName()
Gets the font name set for usage with this FreeTextAnnotation.
- Returns:
The name of the font family used by this FreeTextAnnotation or null if no custom font is set.
-
isUiRotationSupported
boolean isUiRotationSupported()
Returns true if this Annotation can be rotated in the UI.
-
resizeToFitText
void resizeToFitText(@NonNull() AnnotationConfigurationRegistry annotationConfigurationRegistry, @NonNull() Size pageSize)
Resizes the annotation to fit the text. This will update the bounding box of the annotation.
- Parameters:
annotationConfigurationRegistry
- The annotation configuration registry to use for updating the annotation, can be retrieved by PdfFragment.getAnnotationConfigurationRegistry().pageSize
- The size of the page the annotation is on.
-
setFlags
void setFlags(@NonNull() EnumSet<AnnotationFlags> flags)
Sets the annotation flags for this annotation. Since a FreeTextAnnotation with an intent of type FREE_TEXT_CALLOUT does not work with the NOZOOM flag, we will remove it if it exists from the provided flags set
- Parameters:
flags
- Set of annotation flags to be set.
-
setContentSize
void setContentSize(@Nullable() RectF contentSize, boolean adjustedForPageRotation)
Sets the inner bounds that are used when rotating the annotation. In order to keep the size consistent when rotating we need to remember the size when rotated 0° degrees.
Core adds the page rotation to the annotation rotation when handling stamps/free text rotation. So when creating them we can't use the bounding box to initialize the content size when the page they are on is 90° or 270°. We need to flip the width and height so it is correct. The
adjustedForPageRotation
parameter indicates whether this was already done by the calling code or if it should be done automatically when the annotation is attached to the document.- Parameters:
contentSize
- The content size to set in PDF coordinates.adjustedForPageRotation
-true
if the content size was already adjusted for the page rotation,false
if it should be adjusted as soon as the annotation is attached to the document.
-
-
-
-