コード例 #1
0
        public void SetAttribute(XD.TextAttribute a)
        {
            var rtfHelper = new LRTF.RTFHelper();

            var visit = new TextAttributeVisitor {
                FontTextAttribute = attribute => {
                    if (!string.IsNullOrEmpty(attribute.Font.Family))
                    {
                        Controller.SetFontFamiliy(attribute.Font.Family);
                    }
                    if (attribute.Font.Size > 0)
                    {
                        Controller.SetFontSize((int)attribute.Font.Size);
                    }
                },

                FontDataAttribute = attribute => {
                    if (!string.IsNullOrEmpty(attribute.FontFamily))
                    {
                        Controller.SetFontFamiliy(attribute.FontFamily);
                    }
                    if (attribute.FontSize > 0)
                    {
                        Controller.SetFontSize((int)attribute.FontSize);
                    }
                },

                FontWeightTextAttribute = attribute =>
                                          Controller.SetEditorSelectedRTF(
                    source => rtfHelper.SetAttributes(source, Convert(attribute.Weight))),

                FontStyleTextAttribute = attribute =>
                                         Controller.SetEditorSelectedRTF(
                    source => rtfHelper.SetAttributes(source, Convert(attribute.Style))),

                StrikethroughTextAttribute = attribute => {
                    if (attribute.Strikethrough)
                    {
                        Controller.SetEditorSelectedRTF(
                            source => rtfHelper.SetAttributes(source, LRTF.FontStyle.Strikeout));
                    }
                },

                UnderlineTextAttribute = attribute => {
                    if (attribute.Underline)
                    {
                        Controller.SetEditorSelectedRTF(
                            source => rtfHelper.SetAttributes(source, LRTF.FontStyle.Underline));
                    }
                },
                BackgroundTextAttribute = attribute => { },
                ColorTextAttribute      = attribute => {}
            };

            visit.Visit(a);
        }
コード例 #2
0
        public void SetAttribute(XD.TextAttribute a)
        {
            var range = new TextRange(TextBox.Selection.Start, TextBox.Selection.End);

            var visit = new TextAttributeVisitor {
                FontTextAttribute = attribute => {
                    if (!string.IsNullOrEmpty(attribute.Font.Family))
                    {
                        range.ApplyPropertyValue(FlowDocument.FontFamilyProperty, attribute.Font.Family);
                    }
                    if (attribute.Font.Size > 0)
                    {
                        range.ApplyPropertyValue(FlowDocument.FontSizeProperty, attribute.Font.Size);
                    }
                },

                FontDataAttribute = attribute => {
                    if (!string.IsNullOrEmpty(attribute.FontFamily))
                    {
                        range.ApplyPropertyValue(FlowDocument.FontFamilyProperty, attribute.FontFamily);
                    }
                    if (attribute.FontSize > 0)
                    {
                        range.ApplyPropertyValue(FlowDocument.FontSizeProperty, attribute.FontSize);
                    }
                },
                FontWeightTextAttribute = attribute =>
                                          range.ApplyPropertyValue(FlowDocument.FontWeightProperty, attribute.Weight.ToWpfFontWeight()),

                FontStyleTextAttribute = attribute =>
                                         range.ApplyPropertyValue(FlowDocument.FontStyleProperty, attribute.Style.ToWpfFontStyle()),

                StrikethroughTextAttribute = attribute =>
                                             TextDecoration(range, SW.TextDecorations.Strikethrough, attribute.Strikethrough),

                UnderlineTextAttribute = attribute =>
                                         TextDecoration(range, SW.TextDecorations.Underline, attribute.Underline),

                BackgroundTextAttribute = attribute =>
                                          range.ApplyPropertyValue(FlowDocument.BackgroundProperty, new SWM.SolidColorBrush(attribute.Color.ToWpfColor())),

                ColorTextAttribute = attribute =>
                                     range.ApplyPropertyValue(FlowDocument.ForegroundProperty, new SWM.SolidColorBrush(attribute.Color.ToWpfColor())),
            };

            visit.Visit(a);
        }