Select to view content in your preferred language

PrintTask with Text Graphic

2485
1
Jump to solution
12-05-2013 10:10 AM
dmacq
by
Occasional Contributor
I used the tip in this thread to solve my disappearing text when printing issue:

http://forums.arcgis.com/threads/85345-PrintTask-With-Text-Graphics-Containing-Custom-Attributes-Err...

However, as mentioned, clearing my attributes effectively cleared my text graphic. I'm now creating a new TextSymbol for each text graphic, but as I'm unable to control font weight and style, I followed first option in the following thread and created a new TextSymbol, inheriting from MarkerSymbol.

http://forums.arcgis.com/threads/27372-how-to-define-fontstyle-for-textsymbol?p=91150&viewfull=1#pos...

Now, my text symbols show up as point graphics when printed. When using a typical TextSymbol, the text prints fine.  I'm sure I'm missing something when subclassing, I'm just not sure what.  Any help would be greatly appreciated.

public class MyTextSymbol : MarkerSymbol     {          public MyTextSymbol()         {             TextSymbol textSymbol = new TextSymbol();             this.ControlTemplate = textSymbol.ControlTemplate;              this.FontFamily = new FontFamily("Arial");             this.FontSize = 12;             this.FontStyle = FontStyles.Normal;             this.FontWeight = FontWeights.Normal;             this.TextDecorations = null;         }          public String Text         {             get { return GetValue(TextProperty) as String; }             set { SetValue(TextProperty, value); }         }          /// <summary>         /// Identifies the <see cref="Text"/> dependency property.         /// </summary>         public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(String), typeof(MyTextSymbol), new PropertyMetadata(OnTextPropertyChanged));          private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             String text = e.NewValue as String;         }           public Double? FontSize         {             get { return GetValue(FontSizeProperty) as Double?; }             set { SetValue(FontSizeProperty, value); }         }          /// <summary>         /// Identifies the <see cref="FontSize"/> dependency property.         /// </summary>         public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register("FontSize", typeof(Double), typeof(MyTextSymbol), new PropertyMetadata(OnFontSizePropertyChanged));          private static void OnFontSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             Double? fontSize = e.NewValue as Double?;         }           public FontFamily FontFamily         {             get { return GetValue(FontFamilyProperty) as FontFamily; }             set { SetValue(FontFamilyProperty, value); }         }          /// <summary>         /// Identifies the <see cref="FontFamily"/> dependency property.         /// </summary>         public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(MyTextSymbol), new PropertyMetadata(OnFontFamilyPropertyChanged));          private static void OnFontFamilyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             FontFamily fontFamily = e.NewValue as FontFamily;         }           public FontStyle? FontStyle         {             get { return GetValue(FontStyleProperty) as FontStyle?; }             set { SetValue(FontStyleProperty, value); }         }          /// <summary>         /// Identifies the <see cref="FontStyle"/> dependency property.         /// </summary>         public static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(MyTextSymbol), new PropertyMetadata(OnFontStylePropertyChanged));          private static void OnFontStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             FontStyle? fontStyle = e.NewValue as FontStyle?;         }           public FontWeight? FontWeight         {             get { return GetValue(FontWeightProperty) as FontWeight?; }             set { SetValue(FontWeightProperty, value); }         }          /// <summary>         /// Identifies the <see cref="FontWeight"/> dependency property.         /// </summary>         public static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register("FontWeight", typeof(FontWeight), typeof(MyTextSymbol), new PropertyMetadata(OnFontWeightPropertyChanged));          private static void OnFontWeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             FontWeight? fontWeight = e.NewValue as FontWeight?;         }           public TextDecorationCollection TextDecorations         {             get { return GetValue(TextDecorationsProperty) as TextDecorationCollection; }             set { SetValue(TextDecorationsProperty, value); }         }          /// <summary>         /// Identifies the <see cref="TextDecorations"/> dependency property.         /// </summary>         public static readonly DependencyProperty TextDecorationsProperty = DependencyProperty.Register("TextDecorations", typeof(TextDecorationCollection), typeof(MyTextSymbol), new PropertyMetadata(OnTextDecorationsPropertyChanged));          private static void OnTextDecorationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)         {             TextDecorationCollection textDecorations = e.NewValue as TextDecorationCollection;         }      }
0 Kudos
1 Solution

Accepted Solutions
dmacq
by
Occasional Contributor
In order for a custom text symbol to work with the print task, it's necessary to implement IJsonSerializable and create a ToJson method in your class that builds the necessary JSON style information. I tried serializing the class to JSON with the built-in tools, but ran into issues because MarkerSymbol isn't marked for serialization. For now, I'm building the JSON string "by hand".

View solution in original post

0 Kudos
1 Reply
dmacq
by
Occasional Contributor
In order for a custom text symbol to work with the print task, it's necessary to implement IJsonSerializable and create a ToJson method in your class that builds the necessary JSON style information. I tried serializing the class to JSON with the built-in tools, but ran into issues because MarkerSymbol isn't marked for serialization. For now, I'm building the JSON string "by hand".
0 Kudos