From c084d39d394d2314dc1b250c02e249936e093607 Mon Sep 17 00:00:00 2001 From: dirk Date: Mon, 27 Jan 2014 19:08:45 +0000 Subject: [PATCH] Added text direction to Wand and added DrawableTextDirection to Magick++. --- Magick++/lib/Drawable.cpp | 32 +++++++++++++ Magick++/lib/Magick++/Drawable.h | 20 ++++++++ MagickCore/draw.c | 14 ++++++ MagickWand/drawing-wand.c | 78 +++++++++++++++++++++++++++++++- MagickWand/drawing-wand.h | 4 ++ 5 files changed, 147 insertions(+), 1 deletion(-) diff --git a/Magick++/lib/Drawable.cpp b/Magick++/lib/Drawable.cpp index 22da085e0..fbf2020f8 100644 --- a/Magick++/lib/Drawable.cpp +++ b/Magick++/lib/Drawable.cpp @@ -1354,6 +1354,38 @@ Magick::DrawableBase* Magick::DrawableTextDecoration::copy() const return new DrawableTextDecoration(*this); } +// DrawableTextDirection +Magick::DrawableTextDirection::DrawableTextDirection( + DirectionType direction_) + : _direction(direction_) +{ +} + +Magick::DrawableTextDirection::~DrawableTextDirection(void) +{ +} + +void Magick::DrawableTextDirection::operator()( + MagickCore::DrawingWand *context_) const +{ + DrawSetTextDirection(context_,_direction); +} + +void Magick::DrawableTextDirection::direction(DirectionType direction_) +{ + _direction=direction_; +} + +Magick::DirectionType Magick::DrawableTextDirection::direction(void) const +{ + return(_direction); +} + +Magick::DrawableBase *Magick::DrawableTextDirection::copy() const +{ + return new DrawableTextDirection(*this); +} + // DrawableTextInterlineSpacing Magick::DrawableTextInterlineSpacing::DrawableTextInterlineSpacing( double spacing_) diff --git a/Magick++/lib/Magick++/Drawable.h b/Magick++/lib/Magick++/Drawable.h index 59d203690..e35f829c7 100644 --- a/Magick++/lib/Magick++/Drawable.h +++ b/Magick++/lib/Magick++/Drawable.h @@ -1986,6 +1986,26 @@ private: DecorationType _decoration; }; + // Render text right-to-left or left-to-right. + class MagickPPExport DrawableTextDirection : public DrawableBase + { + public: + + DrawableTextDirection(DirectionType direction_); + + ~DrawableTextDirection(void); + + void operator()(MagickCore::DrawingWand *context_) const; + + void direction(DirectionType direction_); + DirectionType direction(void) const; + + DrawableBase* copy() const; + + private: + DirectionType _direction; + }; + // Specify text inter-line spacing class MagickPPExport DrawableTextInterlineSpacing : public DrawableBase { diff --git a/MagickCore/draw.c b/MagickCore/draw.c index 56649cad8..30ef126c2 100644 --- a/MagickCore/draw.c +++ b/MagickCore/draw.c @@ -1961,6 +1961,20 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, graphic_context[n]->decorate=(DecorationType) decorate; break; } + if (LocaleCompare("direction",keyword) == 0) + { + ssize_t + direction; + + GetMagickToken(q,&q,token); + direction=ParseCommandOption(MagickDirectionOptions,MagickFalse, + token); + if (direction == -1) + status=MagickFalse; + else + graphic_context[n]->direction=(DirectionType) direction; + break; + } status=MagickFalse; break; } diff --git a/MagickWand/drawing-wand.c b/MagickWand/drawing-wand.c index 440d04bb7..a3ef2f047 100644 --- a/MagickWand/drawing-wand.c +++ b/MagickWand/drawing-wand.c @@ -2298,6 +2298,38 @@ WandExport DecorationType DrawGetTextDecoration(const DrawingWand *wand) % % % % % % +% D r a w G e t T e x t D i r e c t i o n % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DrawGetTextDirection() returns the direction that will be used when +% annotating with text. +% +% The format of the DrawGetTextDirection method is: +% +% DirectionType DrawGetTextDirection(const DrawingWand *wand) +% +% A description of each parameter follows: +% +% o wand: the drawing wand. +% +*/ +WandExport DirectionType DrawGetTextDirection(const DrawingWand *wand) +{ + assert(wand != (const DrawingWand *) NULL); + assert(wand->signature == WandSignature); + if (wand->debug != MagickFalse) + (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); + return(CurrentContext->direction); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % D r a w G e t T e x t E n c o d i n g % % % % % @@ -5914,7 +5946,51 @@ WandExport void DrawSetTextDecoration(DrawingWand *wand, MagickDecorateOptions,(ssize_t) decoration)); } } - + + /* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% D r a w S e t T e x t D i r e c t i o n % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DrawSetTextDirection() specifies the direction to be used when +% annotating with text. +% +% The format of the DrawSetTextDirection method is: +% +% void DrawSetTextDirection(DrawingWand *wand, +% const DirectionType direction) +% +% A description of each parameter follows: +% +% o wand: the drawing wand. +% +% o direction: text direction. One of RightToLeftDirection, +% LeftToRightDirection +% +*/ +WandExport void DrawSetTextDirection(DrawingWand *wand, + const DirectionType direction) +{ + assert(wand != (DrawingWand *) NULL); + assert(wand->signature == WandSignature); + + if (wand->debug != MagickFalse) + (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); + if ((wand->filter_off != MagickFalse) || + (CurrentContext->direction != direction)) + { + CurrentContext->direction=direction; + (void) MvgPrintf(wand,"direction '%s'\n",CommandOptionToMnemonic( + MagickDirectionOptions,(ssize_t) direction)); + } +} + /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % diff --git a/MagickWand/drawing-wand.h b/MagickWand/drawing-wand.h index c5af07689..aeeb66426 100644 --- a/MagickWand/drawing-wand.h +++ b/MagickWand/drawing-wand.h @@ -44,6 +44,9 @@ extern WandExport ClipPathUnits extern WandExport DecorationType DrawGetTextDecoration(const DrawingWand *); +extern WandExport DirectionType + DrawGetTextDirection(const DrawingWand *); + extern WandExport double DrawGetFillAlpha(const DrawingWand *), DrawGetFontSize(const DrawingWand *), @@ -207,6 +210,7 @@ extern WandExport void DrawSetTextAlignment(DrawingWand *,const AlignType), DrawSetTextAntialias(DrawingWand *,const MagickBooleanType), DrawSetTextDecoration(DrawingWand *,const DecorationType), + DrawSetTextDirection(DrawingWand *,const DirectionType), DrawSetTextEncoding(DrawingWand *,const char *), DrawSetTextUnderColor(DrawingWand *,const PixelWand *), DrawSetViewbox(DrawingWand *,const double,const double,const double, -- 2.50.1