Class Text
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
Simple Text object, Implements IGeoObject.
public class Text : IGeoObjectImpl, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, IFeedBack, ICloneable, IColorDef, ISerializable, IJsonSerialize
- Inheritance
-
Text
- Implements
- Inherited Members
Constructors
Text()
Protected constructor; use Construct() to create a text. The text starts with the line direction XAxis, the glyph direction YAxis, the regular font style and the alignment Baseline. Whether the text is displayed as outline paths or as filled faces comes from the global setting "Font.DisplayMode".
protected Text()
Text(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Text(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructor
Provide a delegate here if you want your Text derived class to be created each time CADability creates a text.
public static Text.ConstructionDelegate Constructor
Field Value
OnPaintTo3D
Hook to replace the painting of texts: when set, PaintTo3D(IPaintTo3D) calls it first and does nothing more when it returns true. The hook is static, so it applies to every text of the process.
public static Text.PaintTo3DDelegate OnPaintTo3D
Field Value
Properties
Alignment
Sets or gets the horizontal (or in direction of LineDirection) alignement of the text.
public Text.AlignMode Alignment { get; set; }
Property Value
Bold
Gets or sets the bold property of the text font.
public bool Bold { get; set; }
Property Value
ColorDef
The color of the text, see ColorDef. Setting it discards the cached display data, raises the change events as a change of an attribute and is undoable; setting null is ignored. A color with fromParent is replaced by the corresponding color of the Block the text belongs to.
public ColorDef ColorDef { get; set; }
Property Value
ColumnWidth
Width of the text column for automatic word wrapping (in world units, e.g. from a DXF MTEXT). The displayed text is broken into additional lines at word boundaries so that no line gets wider than this value. 0.0 (the default) means no automatic wrapping, only explicit line breaks ("\n") are used.
public double ColumnWidth { get; set; }
Property Value
Font
Gets or sets the font used for this text object
public string Font { get; set; }
Property Value
GlyphAngle
Gets or sets the angle of the characters vertical direction in respect to the horizontal direction. The default value is 90°, different angles create different italic fonts.
public Angle GlyphAngle { get; set; }
Property Value
GlyphDirection
Gets or sets the direction of the vertical character parts. This direction is usually perpendicular to the LineDirection, but can be modified to produce italic characters of any angle. The Italic property in contrary uses the typefont italic capabilities which are more sophisticated.
public GeoVector GlyphDirection { get; set; }
Property Value
GlyphDirectionKeepSize
Gets or sets the GlyphDirection without changing its length: only the direction of the value is used, the size of the text stays as it is. A null vector or a vector parallel to the LineDirection is ignored. Setting it raises the change events and is undoable. The property grid uses this property when the glyph direction is edited.
public GeoVector GlyphDirectionKeepSize { get; set; }
Property Value
Italic
Gets or sets the italic property of the text font.
public bool Italic { get; set; }
Property Value
LineAlignment
Sets or gets the vertical alignement of the text.
public Text.LineAlignMode LineAlignment { get; set; }
Property Value
LineDirection
Gets or sets the line direction of the text. Default is XAxis. Setting the line direction does not modify the GlyphDirection of the text, so you usually will have to change both. It also affects the aspect ratio of the text, which is defined by the length of the line direction and the length of the glyph direction. To simply rotate a text better use Modify(ModOp) with a Rotate(GeoPoint, GeoVector, SweepAngle) rotation.
public GeoVector LineDirection { get; set; }
Property Value
LineSpacing
Distance between two baselines of a multi-line text as a factor of the text size. 0.0 (the default) means the natural line spacing of the font is used.
public double LineSpacing { get; set; }
Property Value
Location
Gets or sets the location of the text. The value of this point is interpreted according to the values of the Alignmentand LineAlignment properties.
public GeoPoint Location { get; set; }
Property Value
PreferredStyle
Returns the preferred style for this objects, see Style.EDefaultFor.
public override Style.EDefaultFor PreferredStyle { get; }
Property Value
Strikeout
Gets or sets the strikeout property of the text font.
public bool Strikeout { get; set; }
Property Value
TextSize
Gets or sets the size of this text object.
public double TextSize { get; set; }
Property Value
TextString
Gets or sets the text string that is displayed with this object.
public string TextString { get; set; }
Property Value
Underline
Gets or sets the underline property of the text font.
public bool Underline { get; set; }
Property Value
Methods
ClearFontCache()
Releases the display lists of the text glyphs, which are shared by all texts and all views, and empties the font cache. Call it when the IPaintTo3D that recorded the glyphs can no longer be used, i.e. when the renderer is switched or its graphics device was lost. The glyph lists are disposed with Dispose(), so call it while the old renderer can still handle that (e.g. with its OpenGL context current), or make its lists ignore a lost device. The display lists of the models contain the glyph lists, so they must be rebuilt as well, see InvalidateDisplayLists().
public static void ClearFontCache()
Clone()
Clones this GeoObject.
public override IGeoObject Clone()
Returns
- IGeoObject
the cloned GeoObject
Construct()
The only way to create a text: there are no public constructors. Calls Constructor when one is registered, otherwise creates a Text. Set at least Font, TextString, Location and TextSize afterwards.
public static Text Construct()
Returns
- Text
the new text
CopyGeometry(IGeoObject)
Copies the geometrical aspects of the given GeoObject to this GeoObject. Both objects must be of the same type. The attributes are not copied.
public override void CopyGeometry(IGeoObject ToCopyFrom)
Parameters
ToCopyFromIGeoObjectGeoObject to copy from
GetAttributeProperties(IFrame)
Implements GetAttributeProperties(IFrame). The default implementation returns ShowProperties for all CADability attributes.
public override IPropertyEntry[] GetAttributeProperties(IFrame Frame)
Parameters
FrameIFramethe frame of the view
Returns
- IPropertyEntry[]
list of IPropertyEntry
GetBoundingCube()
Returns a bounding cube of the object. The object must fir into this cube. There may be a smaller cube that contains the object if it is to expensive to calculate the exact cube.
public override BoundingCube GetBoundingCube()
Returns
- BoundingCube
the bounding cube
GetCenterline()
Returns the center lines of the characters of this text: for each character a Block containing the curves that run through the middle of the strokes of the glyph (computed from the outline with ShapeMiddelLine), positioned in world coordinates like the text itself. Suited for single stroke output such as engraving, where GetOutline() would give the two sides of each stroke. Not used by CADability itself.
public virtual GeoObjectList GetCenterline()
Returns
- GeoObjectList
one block per character in the order of the text; line breaks produce no entry
GetExtent(Projection, ExtentPrecision)
Returns the 2d extent of the object as it appears in the given projection, in the coordinates of the projection's plane (not in pixels).
public override BoundingRect GetExtent(Projection projection, ExtentPrecision extentPrecision)
Parameters
projectionProjectionthe projection
extentPrecisionExtentPrecisionExact for the exact extent, Raw for a quick estimate that may be larger
Returns
- BoundingRect
the extent in the projection's 2d coordinates
GetExtent(double)
Gets the 3-dimensional extent of an object
public override BoundingCube GetExtent(double precision)
Parameters
precisiondoublePrecision of the test
Returns
- BoundingCube
The minmax cube
GetObjectData(IJsonWriteData)
Writes the data of this base class (user data, layer, style, user attributes and actuator) for the JSON serialization (IJsonSerialize). Derived classes override it, call the base implementation and add their own properties.
public override void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDatareceives the data
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetOutline()
Returns a list of objects that define the outline (and holes) of this text. The global setting "Font.Precision" defines the precision of the outline, if the precision is 3 (fine) then splines can occur in the outline. If the precision is 1 or 2 (raw, middle) the splines are approximated.
public virtual GeoObjectList GetOutline()
Returns
- GeoObjectList
List of curves describing the outline of this text object
GetQuadTreeItem(Projection, ExtentPrecision)
Returns an item for a 2d quad tree of the projected objects, used for hit tests in a projection: it knows the 2d extent of the object, whether a 2d rectangle hits it, and the depth (z position) of the object at a 2d point. Composite objects (blocks, solids, paths) return a collection of the items of their parts.
public override IQuadTreeInsertableZ GetQuadTreeItem(Projection projection, ExtentPrecision extentPrecision)
Parameters
projectionProjectionthe projection
extentPrecisionExtentPrecisionprecision of the extent, see GetExtent(Projection, ExtentPrecision)
Returns
- IQuadTreeInsertableZ
the item for the quad tree
GetShapes()
Returns the shapes of all characters of this text. The characters are appropriatly spaced, but the text size and glyphdirection is not taken into account
public CompoundShape[] GetShapes()
Returns
GetShowProperties(IFrame)
Should be overridden and return a IPropertyEntry derived object that handles the display and modification of the properties of the IGeoObject derived object. Default implementation return null.
public override IPropertyEntry GetShowProperties(IFrame Frame)
Parameters
FrameIFrame
Returns
HitTest(ref BoundingCube, double)
Tests whether an object is touched by the provided cube
public override bool HitTest(ref BoundingCube cube, double precision)
Parameters
cubeBoundingCubeTo test with
precisiondoubleRequired precision
Returns
- bool
true if the object strikes the cube
HitTest(Projection, BoundingRect, bool)
Tests whether an object is inside or touched by the rectangle when projected with the provided projection
public override bool HitTest(Projection projection, BoundingRect rect, bool onlyInside)
Parameters
projectionProjectionThe projection for the test
rectBoundingRectThe rectangle to test the position
onlyInsidebooltrue: the object must be totaly inside the rectangle, false: the object must be totaly or partially inside the rectangle
Returns
- bool
true when the test succeedes, false otherwise
HitTest(PickArea, bool)
Tests whether an object is inside or touched by the provided area
public override bool HitTest(Projection.PickArea area, bool onlyInside)
Parameters
areaProjection.PickAreaThe area to check for
onlyInsidebooltrue: the object must be totaly inside the area, false: the object must be totaly or partially inside the area
Returns
- bool
true when the test succeedes, false otherwise
Modify(ModOp)
Modifies this GeoObject with the given modification operation (includes moving, rotating, reflecting, scaling etc.).
public override void Modify(ModOp m)
Parameters
mModOpOperation to be applied
PaintTo3D(IPaintTo3D)
Paints the object with the methods of paintTo3D: lines, triangles, text... The views implement
IPaintTo3D (with OpenGL or GDI) and collect what the object paints in a display list, so this is
called rarely, after PrepareDisplayList(double) has done the expensive work (triangulation, approximation).
public override void PaintTo3D(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3Dwhere to paint
PaintTo3DList(IPaintTo3D, ICategorizedDislayLists)
Adds this object as a whole to the display lists, in the category of its layer. Suitable for simple objects like curves and text; composite objects (solids, shells, blocks) override it and add their parts by category.
public override void PaintTo3DList(IPaintTo3D paintTo3D, ICategorizedDislayLists lists)
Parameters
paintTo3DIPaintTo3Dthe paint interface of the view
listsICategorizedDislayListsthe display lists to add to
Position(GeoPoint, GeoVector, double)
Returns the smallest parameter value (l) where the provided line hits the object so that the point
fromHere + l * direction is on or close to the object. The result may be negative.
Return double.MaxValue if there is no such point.
public override double Position(GeoPoint fromHere, GeoVector direction, double precision)
Parameters
fromHereGeoPointStartpoint of the line
directionGeoVectorDirection of the line
precisiondoublePrecision for the test
Returns
- double
Position on the line
PrePaintTo3D(IPaintTo3D)
Called before PaintTo3D(IPaintTo3D), outside of the display list that collects what PaintTo3D paints. Override it for work that must not go into that list, e.g. painting that needs a display list of its own. The default implementation does nothing.
public override void PrePaintTo3D(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3Dthe paint interface of the view
PrepareDisplayList(double)
Called before PaintTo3D(IPaintTo3D) is called, should implement the time consuming work for the display (like calculationg the triangulation of Faces or Polylines of Curves). Not normally used by user code.
public override void PrepareDisplayList(double precision)
Parameters
precisiondoubleRequired precision
SetBounds(GeoPoint, GeoPoint, GeoPoint)
Modifies the direction, size and aspect ratio of the text so that the text will fit inside the parallelogram defined by the provided parameters.
public void SetBounds(GeoPoint ll, GeoPoint lr, GeoPoint ul)
Parameters
llGeoPointPoint for the lower left position of the text
lrGeoPointPoint for the lower right position of the text
ulGeoPointPoint for the upper left position of the text
SetDirections(GeoVector, GeoVector)
Sets LineDirection and GlyphDirection at once, without the checks of the individual properties. The vectors must not be parallel; their lengths define the size and the aspect ratio of the text. Raises the change events and is undoable.
public void SetDirections(GeoVector lineDirection, GeoVector glyphDirection)
Parameters
lineDirectionGeoVectorthe direction of the lines of the text
glyphDirectionGeoVectorthe direction of the vertical parts of the characters
SetLineDirKeepGlyphAngle(GeoVector)
Sets the line direction and rotates the glyph direction along with it, so that the GlyphAngle
between both and the lengths of both (the size and the aspect ratio of the text) stay as they are: the glyph
direction is recomputed by rotating the new line direction about the normal of the text's plane by the glyph
angle. Only the direction of ld is used, its length is ignored; a null vector is ignored
altogether. Raises the change events and is undoable. The property grid uses this method when the line direction
is edited.
public void SetLineDirKeepGlyphAngle(GeoVector ld)
Parameters
ldGeoVectorthe new line direction
SetObjectData(IJsonReadData)
Reads the data written by GetObjectData(IJsonWriteData) back from the JSON serialization. Derived classes override it, call the base implementation and read their own properties. Objects referenced by the data may still be incomplete at this time, see IJsonSerializeDone.
public override void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDataprovides the data