DGtal 1.4.0
Loading...
Searching...
No Matches
LibBoard::Text Struct Reference

A piece of text. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Text:
[legend]

Public Member Functions

 Text (double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
 
 Text (double x, double y, const std::string &text, const Fonts::Font font, const std::string &svgFont, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
 
const std::string & name () const
 
Point center () const
 
Textrotate (double angle, const Point &center)
 
Text rotated (double angle, const Point &center) const
 
Textrotate (double angle)
 
Text rotated (double angle) const
 
Texttranslate (double dx, double dy)
 
Text translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Text scaled (double sx, double sy) const
 
Text scaled (double s) const
 
void scaleAll (double s)
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
Rect boundingBox () const
 
Textclone () const
 
- Public Member Functions inherited from LibBoard::Shape
 Shape (DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
bool filled () const
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Protected Attributes

Point _position
 
std::string _text
 
Fonts::Font _font
 
std::string _svgFont
 
double _angle
 
double _size
 
double _xScale
 
double _yScale
 
- Protected Attributes inherited from LibBoard::Shape
int _depth
 
DGtal::Color _penColor
 
DGtal::Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Static Private Attributes

static const std::string _name
 

Additional Inherited Members

- Public Types inherited from LibBoard::Shape
enum  LineCap { ButtCap = 0 , RoundCap , SquareCap }
 
enum  LineJoin { MiterJoin = 0 , RoundJoin , BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0 , DashStyle , DotStyle , DashDotStyle ,
  DashDotDotStyle , DashDotDotDotStyle
}
 
- Protected Member Functions inherited from LibBoard::Shape
std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties () const
 
void setCairoDashStyle (cairo_t *cr, LineStyle type) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 

Detailed Description

A piece of text.

The text structure.

Definition at line 1574 of file Board/Shapes.h.

Constructor & Destructor Documentation

◆ Text() [1/2]

LibBoard::Text::Text ( double x,
double y,
const std::string & text,
const Fonts::Font font,
double size,
DGtal::Color color = DGtal::Color::Black,
int depthValue = -1 )
inline

Create a Text sctucture.

Parameters
xx
yy
texttext
fontfont
sizeThe font size expressed in 1/72 inches.
colorcolor
depthValuedepth

Definition at line 1588 of file Board/Shapes.h.

1594 : Shape( color, DGtal::Color::None, 1.0, SolidStyle, ButtCap, MiterJoin, depthValue ),
1595 _position( x, y ), _text( text ), _font( font ),
1596 _angle( 0.0 ), _size( size ),
1597 _xScale( 1.0 ), _yScale( 1.0 ) { }
static const Color None
Definition Color.h:412
std::string _text
Fonts::Font _font
Astroid2D< Space > Shape

Referenced by clone(), rotated(), rotated(), scaled(), scaled(), and translated().

◆ Text() [2/2]

LibBoard::Text::Text ( double x,
double y,
const std::string & text,
const Fonts::Font font,
const std::string & svgFont,
double size,
DGtal::Color color = DGtal::Color::Black,
int depthValue = -1 )
inline

Create a Text sctucture.

Parameters
xx
yy
texttext
fontfont
svgFontThe font family for an SVG file. (E.g. "Verdana, Arial" or "'Time New Roman', Serif" )
sizeThe font size expressed in 1/72 inches.
colorcolor
depthValuedepth

Definition at line 1613 of file Board/Shapes.h.

1620 : Shape( color, DGtal::Color::None, 1.0, SolidStyle, ButtCap, MiterJoin, depthValue ),
1621 _position( x, y ),
1622 _text( text ), _font( font ), _svgFont( svgFont ),
1623 _angle( 0.0 ),
1624 _size( size ),
1625 _xScale( 1.0 ), _yScale( 1.0 ) { }
std::string _svgFont

Member Function Documentation

◆ boundingBox()

Rect LibBoard::Text::boundingBox ( ) const
virtual

Returns the bounding box of the figure.

Returns
The rectangle of the bounding box.

Implements LibBoard::Shape.

Definition at line 2759 of file Shapes.cpp.

2760{
2761 return Rect( _position.x, _position.y, 0, 0 );
2762}
double y
Definition Point.h:30
double x
Definition Point.h:29

References _position, LibBoard::Point::x, and LibBoard::Point::y.

◆ center()

Point LibBoard::Text::center ( ) const
virtual

Returns the gravity center of the shape.

Returns
The center of the shape.

Implements LibBoard::Shape.

Definition at line 2535 of file Shapes.cpp.

2535 {
2536 return _position;
2537}

References _position.

◆ clone()

Text * LibBoard::Text::clone ( ) const
virtual

Return a copy of the shape.

Returns
copye of the shape.

Implements LibBoard::Shape.

Definition at line 2623 of file Shapes.cpp.

2623 {
2624 return new Text(*this);
2625}
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)

References Text().

◆ flushCairo()

void LibBoard::Text::flushCairo ( cairo_t * cr,
const TransformCairo & transform ) const
virtual

Writes the cairo code of the shape in a cairo drawing context according to a transform.

Parameters
crThe cairo drawing context.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Definition at line 2694 of file Shapes.cpp.

2696{
2697}

◆ flushFIG()

void LibBoard::Text::flushFIG ( std::ostream & stream,
const TransformFIG & transform,
std::map< DGtal::Color, int > & colormap ) const
virtual

Writes the FIG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.
colormapA colormap.

Implements LibBoard::Shape.

Definition at line 2641 of file Shapes.cpp.

2644{
2645 stream << "4 0 " ;
2646 // Color, depth, unused, Font
2647 stream << colormap[ _penColor ] << " " << transform.mapDepth( _depth ) << " -1 " << _font << " ";
2648 // Font size, Angle, Font flags
2649 stream << _size << " " << _angle << " 4 ";
2650 // Height
2651 stream << static_cast<int>( _size * 135 / 12.0 ) << " ";
2652 // Width
2653 stream << static_cast<int>( _text.size() * _size * 135 / 12.0 ) << " ";
2654 // x y
2655 stream << static_cast<int>( transform.mapX( _position.x ) ) << " "
2656 << static_cast<int>( transform.mapY( _position.y ) ) << " ";
2657 stream << _text << "\\001\n";
2658}
DGtal::Color _penColor

References _angle, LibBoard::Shape::_depth, _font, LibBoard::Shape::_penColor, _position, _size, _text, LibBoard::Point::x, and LibBoard::Point::y.

◆ flushPostscript()

void LibBoard::Text::flushPostscript ( std::ostream & stream,
const TransformEPS & transform ) const
virtual

Writes the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Definition at line 2628 of file Shapes.cpp.

2630{
2631 stream << "\n% Text\n";
2632 stream << "gs /" << PSFontNames[ _font ] << " ff " << _size << " scf sf";
2633 stream << " " << transform.mapX( _position.x ) << " " << transform.mapY( _position.y ) << " m";
2634 if ( _angle != 0.0 ) stream << " " << (_angle/M_PI)*180.0 << " rot ";
2635 stream << " (" << _text << ")"
2636 << " " << _penColor.postscript() << " srgb"
2637 << " sh gr" << std::endl;
2638}
std::string postscript() const
Definition Color.cpp:150
const char * PSFontNames[]
Definition PSFonts.cpp:16

References _angle, _font, LibBoard::Shape::_penColor, _position, _size, _text, DGtal::Color::postscript(), LibBoard::PSFontNames, LibBoard::Point::x, and LibBoard::Point::y.

◆ flushSVG()

void LibBoard::Text::flushSVG ( std::ostream & stream,
const TransformSVG & transform ) const
virtual

Writes the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Definition at line 2661 of file Shapes.cpp.

2663{
2664 if ( _angle != 0.0f ) {
2665 stream << "<g transform=\"translate("
2666 << transform.mapX( _position.x ) << ","
2667 << transform.mapY( _position.y ) << ")\" >"
2668 << "<g transform=\"rotate(" << (-_angle*180.0/M_PI) << ")\" >"
2669 << "<text x=\"0\" y=\"0\""
2670 << " font-family=\"" << ( _svgFont.length() ? _svgFont : PSFontNames[ _font ] ) << "\""
2671 << " font-size=\"" << _size << "\""
2672 << " fill=\"" << _penColor.svg() << "\""
2673 << _fillColor.svgAlpha( " fill" )
2674 << _penColor.svgAlpha( " stroke" )
2675 << ">"
2676 << _text
2677 << "</text></g></g>" << std::endl;
2678 } else {
2679 stream << "<text x=\"" << transform.mapX( _position.x )
2680 << "\" y=\"" << transform.mapY( _position.y ) << "\" "
2681 << " font-family=\"" << ( _svgFont.length() ? _svgFont : PSFontNames[ _font ] ) << "\""
2682 << " font-size=\"" << _size << "\""
2683 << " fill=\"" << _penColor.svg() << "\""
2684 << _fillColor.svgAlpha( " fill" )
2685 << _penColor.svgAlpha( " stroke" )
2686 << ">"
2687 << _text
2688 << "</text>" << std::endl;
2689 }
2690}
std::string svg() const
Definition Color.cpp:158
std::string svgAlpha(const char *aPrefix) const
Definition Color.cpp:167
DGtal::Color _fillColor

References _angle, LibBoard::Shape::_fillColor, _font, LibBoard::Shape::_penColor, _position, _size, _svgFont, _text, LibBoard::PSFontNames, DGtal::Color::svg(), DGtal::Color::svgAlpha(), LibBoard::Point::x, and LibBoard::Point::y.

◆ flushTikZ()

void LibBoard::Text::flushTikZ ( std::ostream & stream,
const TransformTikZ & transform ) const
virtual

Writes the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implements LibBoard::Shape.

Definition at line 2701 of file Shapes.cpp.

2703{
2704 // FIXME: honor font-size
2705#define BOLD_FONT 0x01
2706#define ITALIC_FONT 0x02
2707#define MONOSPACE_FONT 0x04
2708#define SANSSERIF_FONT 0x08
2709 char fontTraits[] = {
2710 0, // TimesRoman,
2711 ITALIC_FONT, // TimesItalic,
2712 BOLD_FONT, // TimesBold,
2713 BOLD_FONT | ITALIC_FONT, // TimesBoldItalic,
2714 SANSSERIF_FONT, // AvantGardeBook,
2715 SANSSERIF_FONT | ITALIC_FONT, // AvantGardeBookOblique,
2716 SANSSERIF_FONT, // AvantGardeDemi,
2717 SANSSERIF_FONT | ITALIC_FONT, // AvantGardeDemiOblique,
2718 0, // BookmanLight,
2719 ITALIC_FONT, // BookmanLightItalic,
2720 0, // BookmanDemi,
2721 ITALIC_FONT, // BookmanDemiItalic,
2722 MONOSPACE_FONT, // Courier,
2723 MONOSPACE_FONT | ITALIC_FONT, // CourierOblique,
2724 MONOSPACE_FONT | BOLD_FONT, // CourierBold,
2725 MONOSPACE_FONT | BOLD_FONT | ITALIC_FONT, // CourierBoldOblique,
2726 SANSSERIF_FONT, // Helvetica,
2727 SANSSERIF_FONT | ITALIC_FONT, // HelveticaOblique,
2728 SANSSERIF_FONT | BOLD_FONT, // HelveticaBold,
2729 SANSSERIF_FONT | BOLD_FONT | ITALIC_FONT, // HelveticaBoldOblique,
2730 SANSSERIF_FONT, // HelveticaNarrow,
2731 SANSSERIF_FONT | ITALIC_FONT, // HelveticaNarrowOblique,
2732 SANSSERIF_FONT | BOLD_FONT, // HelveticaNarrowBold,
2733 SANSSERIF_FONT | BOLD_FONT | ITALIC_FONT, // HelveticaNarrowBoldOblique,
2734 0, // NewCenturySchoolbookRoman,
2735 ITALIC_FONT, // NewCenturySchoolbookItalic,
2736 BOLD_FONT, // NewCenturySchoolbookBold,
2737 BOLD_FONT | ITALIC_FONT, // NewCenturySchoolbookBoldItalic,
2738 0, // PalatinoRoman,
2739 ITALIC_FONT, // PalatinoItalic,
2740 BOLD_FONT, // PalatinoBold,
2741 BOLD_FONT | ITALIC_FONT, // PalatinoBoldItalic,
2742 0, // Symbol,
2743 ITALIC_FONT, // ZapfChanceryMediumItalic,
2744 0 // ZapfDingbats
2745 };
2746
2747 stream << "\\path[" << tikzProperties(transform) << "] ("
2748 << transform.mapX( _position.x ) << ',' << transform.mapY( _position.y )
2749 << ") node {"
2750 << (fontTraits[ _font ] & ITALIC_FONT ? "\\itshape " : "")
2751 << (fontTraits[ _font ] & BOLD_FONT ? "\\bfseries " : "")
2752 << (fontTraits[ _font ] & MONOSPACE_FONT ? "\\ttfamily " : "")
2753 << (fontTraits[ _font ] & SANSSERIF_FONT ? "\\sffamily " : "")
2754 << _text
2755 << "};" << std::endl;
2756}
STL namespace.
std::string tikzProperties(const TransformTikZ &transform) const
Definition Shapes.cpp:177

References _font, _position, _text, LibBoard::Shape::tikzProperties(), LibBoard::Point::x, and LibBoard::Point::y.

◆ name()

const std::string & LibBoard::Text::name ( ) const
virtual

Returns the generic name of the shape (e.g., Circle, Rectangle, etc.)

Returns
object name

Reimplemented from LibBoard::Shape.

Definition at line 2529 of file Shapes.cpp.

2530{
2531 return _name;
2532}
static const std::string _name

References _name.

◆ rotate() [1/2]

Text & LibBoard::Text::rotate ( double angle)
virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 2560 of file Shapes.cpp.

2561{
2562 _angle += angle;
2563 if ( _angle < 0 )
2564 while ( _angle < M_PI ) _angle += 2 * M_PI;
2565 if ( _angle > 0 )
2566 while ( _angle > M_PI ) _angle -= 2 * M_PI;
2567 return *this;
2568}

References _angle.

◆ rotate() [2/2]

Text & LibBoard::Text::rotate ( double angle,
const Point & center )
virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 2540 of file Shapes.cpp.

2541{
2542 Point endPos = _position + Point( 10000 * cos( _angle ), 10000 * sin( _angle ) );
2543 _position.rotate( angle, rotCenter );
2544 endPos.rotate( angle, rotCenter );
2545 Point v = endPos - _position;
2546 v /= v.norm();
2547 if ( v.x >= 0 ) _angle = asin( v.y );
2548 else if ( v.y > 0 ) _angle = (M_PI/2.0) + acos( v.y );
2549 else _angle = (-M_PI/2.0) - acos( -v.y );
2550 return *this;
2551}
Point & rotate(double angle)
Definition Point.h:190
double norm() const
Definition Point.h:221
MyPointD Point

References _angle, _position, LibBoard::Point::norm(), and LibBoard::Point::rotate().

Referenced by rotated(), and rotated().

◆ rotated() [1/2]

Text LibBoard::Text::rotated ( double angle) const

Definition at line 2571 of file Shapes.cpp.

2572{
2573 return Text(*this).rotate( angle );
2574}

References rotate(), and Text().

◆ rotated() [2/2]

Text LibBoard::Text::rotated ( double angle,
const Point & center ) const

Definition at line 2554 of file Shapes.cpp.

2555{
2556 return Text(*this).rotate( angle, rotCenter );
2557}

References rotate(), and Text().

◆ scale() [1/2]

Shape & LibBoard::Text::scale ( double s)
virtual

Scale the shape along both axis.

Parameters
sThe scale factor along both axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Definition at line 2598 of file Shapes.cpp.

2599{
2600 _xScale = _yScale = s;
2601 return *this;
2602}

References _xScale, and _yScale.

◆ scale() [2/2]

Shape & LibBoard::Text::scale ( double sx,
double sy )
virtual

Scale the shape along the x an y axis.

Parameters
sxThe scale factor along the x axis.
syThe scale factor along the y axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Definition at line 2590 of file Shapes.cpp.

2591{
2592 _xScale = sx;
2593 _yScale = sy;
2594 return *this;
2595}

References _xScale, and _yScale.

◆ scaleAll()

void LibBoard::Text::scaleAll ( double s)
virtual

Scales all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Implements LibBoard::Shape.

Definition at line 2617 of file Shapes.cpp.

2618{
2619 _position *= s;
2620}

References _position.

◆ scaled() [1/2]

Text LibBoard::Text::scaled ( double s) const

Definition at line 2611 of file Shapes.cpp.

2612{
2613 return static_cast<Text &>( Text(*this).scale( s, s ) );
2614}

References Text().

◆ scaled() [2/2]

Text LibBoard::Text::scaled ( double sx,
double sy ) const

Definition at line 2605 of file Shapes.cpp.

2606{
2607 return static_cast<Text &>( Text(*this).scale( sx, sy ) );
2608}

References Text().

◆ translate()

Text & LibBoard::Text::translate ( double dx,
double dy )
virtual

Translate the shape by a given offset.

Parameters
dxThe x offset.
dyThe y offset.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 2577 of file Shapes.cpp.

2578{
2579 _position += Point( dx, dy );
2580 return *this;
2581}

References _position.

◆ translated()

Text LibBoard::Text::translated ( double dx,
double dy ) const

Definition at line 2584 of file Shapes.cpp.

2585{
2586 return static_cast<Text&>( Text(*this).translate( dx, dy ) );
2587}

References Text().

Field Documentation

◆ _angle

double LibBoard::Text::_angle
protected

Definition at line 1694 of file Board/Shapes.h.

Referenced by flushFIG(), flushPostscript(), flushSVG(), rotate(), and rotate().

◆ _font

Fonts::Font LibBoard::Text::_font
protected

Definition at line 1692 of file Board/Shapes.h.

Referenced by flushFIG(), flushPostscript(), flushSVG(), and flushTikZ().

◆ _name

const std::string LibBoard::Text::_name
staticprivate

The generic name of the shape.

Definition at line 1687 of file Board/Shapes.h.

Referenced by name().

◆ _position

Point LibBoard::Text::_position
protected

◆ _size

double LibBoard::Text::_size
protected

Definition at line 1695 of file Board/Shapes.h.

Referenced by flushFIG(), flushPostscript(), and flushSVG().

◆ _svgFont

std::string LibBoard::Text::_svgFont
protected

Definition at line 1693 of file Board/Shapes.h.

Referenced by flushSVG().

◆ _text

std::string LibBoard::Text::_text
protected

Definition at line 1691 of file Board/Shapes.h.

Referenced by flushFIG(), flushPostscript(), flushSVG(), and flushTikZ().

◆ _xScale

double LibBoard::Text::_xScale
protected

Definition at line 1696 of file Board/Shapes.h.

Referenced by scale(), and scale().

◆ _yScale

double LibBoard::Text::_yScale
protected

Definition at line 1697 of file Board/Shapes.h.

Referenced by scale(), and scale().


The documentation for this struct was generated from the following files: