DGtal  0.9.4beta
Public Member Functions | Protected Attributes | Static Private Attributes
LibBoard::Text Struct Reference

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Text:
[legend]
Collaboration 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

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.

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

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 ) { }
Fonts::Font _font
static const Color None
Definition: Color.h:387
std::string _text
Shape(DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
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
Fonts::Font _font
static const Color None
Definition: Color.h:387
std::string _text
Shape(DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)

Member Function Documentation

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 2784 of file Shapes.cpp.

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

2785 {
2786  return Rect( _position.x, _position.y, 0, 0 );
2787 }
double x
Definition: Point.h:29
double y
Definition: Point.h:30
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 2560 of file Shapes.cpp.

References _position.

2560  {
2561  return _position;
2562 }
Text * LibBoard::Text::clone ( ) const
virtual

Return a copy of the shape.

Returns
copye of the shape.

Implements LibBoard::Shape.

Definition at line 2648 of file Shapes.cpp.

References Text().

2648  {
2649  return new Text(*this);
2650 }
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
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 2719 of file Shapes.cpp.

2721 {
2722 }
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 2666 of file Shapes.cpp.

References _angle, LibBoard::Shape::_depth, _font, LibBoard::Shape::_penColor, _position, _size, _text, LibBoard::TransformFIG::mapDepth(), LibBoard::Transform::mapX(), LibBoard::TransformFIG::mapY(), LibBoard::Point::x, and LibBoard::Point::y.

2669 {
2670  stream << "4 0 " ;
2671  // Color, depth, unused, Font
2672  stream << colormap[ _penColor ] << " " << transform.mapDepth( _depth ) << " -1 " << _font << " ";
2673  // Font size, Angle, Font flags
2674  stream << _size << " " << _angle << " 4 ";
2675  // Height
2676  stream << static_cast<int>( _size * 135 / 12.0 ) << " ";
2677  // Width
2678  stream << static_cast<int>( _text.size() * _size * 135 / 12.0 ) << " ";
2679  // x y
2680  stream << static_cast<int>( transform.mapX( _position.x ) ) << " "
2681  << static_cast<int>( transform.mapY( _position.y ) ) << " ";
2682  stream << _text << "\\001\n";
2683 }
Fonts::Font _font
std::string _text
double x
Definition: Point.h:29
double y
Definition: Point.h:30
DGtal::Color _penColor
Definition: Board/Shapes.h:296
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 2653 of file Shapes.cpp.

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

2655 {
2656  stream << "\n% Text\n";
2657  stream << "gs /" << PSFontNames[ _font ] << " ff " << _size << " scf sf";
2658  stream << " " << transform.mapX( _position.x ) << " " << transform.mapY( _position.y ) << " m";
2659  if ( _angle != 0.0 ) stream << " " << (_angle/M_PI)*180.0 << " rot ";
2660  stream << " (" << _text << ")"
2661  << " " << _penColor.postscript() << " srgb"
2662  << " sh gr" << std::endl;
2663 }
const char * PSFontNames[]
Definition: PSFonts.cpp:16
Fonts::Font _font
std::string _text
double x
Definition: Point.h:29
std::string postscript() const
Definition: Color.cpp:132
double y
Definition: Point.h:30
DGtal::Color _penColor
Definition: Board/Shapes.h:296
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 2686 of file Shapes.cpp.

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

2688 {
2689  if ( _angle != 0.0f ) {
2690  stream << "<g transform=\"translate("
2691  << transform.mapX( _position.x ) << ","
2692  << transform.mapY( _position.y ) << ")\" >"
2693  << "<g transform=\"rotate(" << (-_angle*180.0/M_PI) << ")\" >"
2694  << "<text x=\"0\" y=\"0\""
2695  << " font-family=\"" << ( _svgFont.length() ? _svgFont : PSFontNames[ _font ] ) << "\""
2696  << " font-size=\"" << _size << "\""
2697  << " fill=\"" << _penColor.svg() << "\""
2698  << _fillColor.svgAlpha( " fill" )
2699  << _penColor.svgAlpha( " stroke" )
2700  << ">"
2701  << _text
2702  << "</text></g></g>" << std::endl;
2703  } else {
2704  stream << "<text x=\"" << transform.mapX( _position.x )
2705  << "\" y=\"" << transform.mapY( _position.y ) << "\" "
2706  << " font-family=\"" << ( _svgFont.length() ? _svgFont : PSFontNames[ _font ] ) << "\""
2707  << " font-size=\"" << _size << "\""
2708  << " fill=\"" << _penColor.svg() << "\""
2709  << _fillColor.svgAlpha( " fill" )
2710  << _penColor.svgAlpha( " stroke" )
2711  << ">"
2712  << _text
2713  << "</text>" << std::endl;
2714  }
2715 }
std::string _svgFont
const char * PSFontNames[]
Definition: PSFonts.cpp:16
Fonts::Font _font
std::string _text
double x
Definition: Point.h:29
std::string svg() const
Definition: Color.cpp:140
double y
Definition: Point.h:30
DGtal::Color _penColor
Definition: Board/Shapes.h:296
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
std::string svgAlpha(const char *aPrefix) const
Definition: Color.cpp:149
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 2726 of file Shapes.cpp.

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

2728 {
2729  // FIXME: honor font-size
2730 #define BOLD_FONT 0x01
2731 #define ITALIC_FONT 0x02
2732 #define MONOSPACE_FONT 0x04
2733 #define SANSSERIF_FONT 0x08
2734  char fontTraits[] = {
2735  0, // TimesRoman,
2736  ITALIC_FONT, // TimesItalic,
2737  BOLD_FONT, // TimesBold,
2738  BOLD_FONT | ITALIC_FONT, // TimesBoldItalic,
2739  SANSSERIF_FONT, // AvantGardeBook,
2740  SANSSERIF_FONT | ITALIC_FONT, // AvantGardeBookOblique,
2741  SANSSERIF_FONT, // AvantGardeDemi,
2742  SANSSERIF_FONT | ITALIC_FONT, // AvantGardeDemiOblique,
2743  0, // BookmanLight,
2744  ITALIC_FONT, // BookmanLightItalic,
2745  0, // BookmanDemi,
2746  ITALIC_FONT, // BookmanDemiItalic,
2747  MONOSPACE_FONT, // Courier,
2748  MONOSPACE_FONT | ITALIC_FONT, // CourierOblique,
2749  MONOSPACE_FONT | BOLD_FONT, // CourierBold,
2750  MONOSPACE_FONT | BOLD_FONT | ITALIC_FONT, // CourierBoldOblique,
2751  SANSSERIF_FONT, // Helvetica,
2752  SANSSERIF_FONT | ITALIC_FONT, // HelveticaOblique,
2753  SANSSERIF_FONT | BOLD_FONT, // HelveticaBold,
2754  SANSSERIF_FONT | BOLD_FONT | ITALIC_FONT, // HelveticaBoldOblique,
2755  SANSSERIF_FONT, // HelveticaNarrow,
2756  SANSSERIF_FONT | ITALIC_FONT, // HelveticaNarrowOblique,
2757  SANSSERIF_FONT | BOLD_FONT, // HelveticaNarrowBold,
2758  SANSSERIF_FONT | BOLD_FONT | ITALIC_FONT, // HelveticaNarrowBoldOblique,
2759  0, // NewCenturySchoolbookRoman,
2760  ITALIC_FONT, // NewCenturySchoolbookItalic,
2761  BOLD_FONT, // NewCenturySchoolbookBold,
2762  BOLD_FONT | ITALIC_FONT, // NewCenturySchoolbookBoldItalic,
2763  0, // PalatinoRoman,
2764  ITALIC_FONT, // PalatinoItalic,
2765  BOLD_FONT, // PalatinoBold,
2766  BOLD_FONT | ITALIC_FONT, // PalatinoBoldItalic,
2767  0, // Symbol,
2768  ITALIC_FONT, // ZapfChanceryMediumItalic,
2769  0 // ZapfDingbats
2770  };
2771 
2772  stream << "\\path[" << tikzProperties(transform) << "] ("
2773  << transform.mapX( _position.x ) << ',' << transform.mapY( _position.y )
2774  << ") node {"
2775  << (fontTraits[ _font ] & ITALIC_FONT ? "\\itshape " : "")
2776  << (fontTraits[ _font ] & BOLD_FONT ? "\\bfseries " : "")
2777  << (fontTraits[ _font ] & MONOSPACE_FONT ? "\\ttfamily " : "")
2778  << (fontTraits[ _font ] & SANSSERIF_FONT ? "\\sffamily " : "")
2779  << _text
2780  << "};" << std::endl;
2781 }
Fonts::Font _font
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:178
std::string _text
double x
Definition: Point.h:29
double y
Definition: Point.h:30
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 2554 of file Shapes.cpp.

References _name.

2555 {
2556  return _name;
2557 }
static const std::string _name
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 2565 of file Shapes.cpp.

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

2566 {
2567  Point endPos = _position + Point( 10000 * cos( _angle ), 10000 * sin( _angle ) );
2568  _position.rotate( angle, rotCenter );
2569  endPos.rotate( angle, rotCenter );
2570  Point v = endPos - _position;
2571  v /= v.norm();
2572  if ( v.x >= 0 ) _angle = asin( v.y );
2573  else if ( v.y > 0 ) _angle = (M_PI/2.0) + acos( v.y );
2574  else _angle = (-M_PI/2.0) - acos( -v.y );
2575  return *this;
2576 }
Point & rotate(double angle)
Definition: Point.h:183
double norm() const
Definition: Point.h:214
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 2585 of file Shapes.cpp.

References _angle.

2586 {
2587  _angle += angle;
2588  if ( _angle < 0 )
2589  while ( _angle < M_PI ) _angle += 2 * M_PI;
2590  if ( _angle > 0 )
2591  while ( _angle > M_PI ) _angle -= 2 * M_PI;
2592  return *this;
2593 }
Text LibBoard::Text::rotated ( double  angle,
const Point center 
) const

Definition at line 2579 of file Shapes.cpp.

References Text().

2580 {
2581  return Text(*this).rotate( angle, rotCenter );
2582 }
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 LibBoard::Text::rotated ( double  angle) const

Definition at line 2596 of file Shapes.cpp.

References Text().

2597 {
2598  return Text(*this).rotate( angle );
2599 }
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)
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 2615 of file Shapes.cpp.

References _xScale, and _yScale.

2616 {
2617  _xScale = sx;
2618  _yScale = sy;
2619  return *this;
2620 }
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 2623 of file Shapes.cpp.

References _xScale, and _yScale.

2624 {
2625  _xScale = _yScale = s;
2626  return *this;
2627 }
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 2642 of file Shapes.cpp.

References _position.

2643 {
2644  _position *= s;
2645 }
Text LibBoard::Text::scaled ( double  sx,
double  sy 
) const

Definition at line 2630 of file Shapes.cpp.

References Text().

2631 {
2632  return static_cast<Text &>( Text(*this).scale( sx, sy ) );
2633 }
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 LibBoard::Text::scaled ( double  s) const

Definition at line 2636 of file Shapes.cpp.

References Text().

2637 {
2638  return static_cast<Text &>( Text(*this).scale( s, s ) );
2639 }
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 & 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 2602 of file Shapes.cpp.

References _position.

2603 {
2604  _position += Point( dx, dy );
2605  return *this;
2606 }
Text LibBoard::Text::translated ( double  dx,
double  dy 
) const

Definition at line 2609 of file Shapes.cpp.

References Text().

2610 {
2611  return static_cast<Text&>( Text(*this).translate( dx, dy ) );
2612 }
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, DGtal::Color color=DGtal::Color::Black, int depthValue=-1)

Field Documentation

double LibBoard::Text::_angle
protected

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

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

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

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

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

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().

Point LibBoard::Text::_position
protected
double LibBoard::Text::_size
protected

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

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

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

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

Referenced by flushSVG().

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

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

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

double LibBoard::Text::_xScale
protected

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

Referenced by scale().

double LibBoard::Text::_yScale
protected

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

Referenced by scale().


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