Beispiel #1
0
        private void OnClick(object sender, EventArgs e)
        {
            // Initialize the text store.
            if (customTextSource == null)
            {
                customTextSource = new CustomTextSource();
            }

            UpdateFormattedText03();
        }
Beispiel #2
0
        private void UpdateFormattedText(double pixelsPerDip)
        {
            if (!_UILoaded)
            {
                return;
            }
            _textStore = new CustomTextSource(_pixelsPerDip);

            int textStorePosition = 0;

            System.Windows.Point linePosition = new System.Windows.Point(0, 0);
            DrawingGroup         textDest     = new DrawingGroup();
            DrawingContext       dc           = textDest.Open();
            //_textStore.Text = textToFormat.Text();
        }
        public void Should_FormatLine_With_DrawableRuns()
        {
            var defaultRunProperties = new GenericTextRunProperties(Typeface.Default, foregroundBrush: Brushes.Black);
            var paragraphProperties  = new GenericTextParagraphProperties(defaultRunProperties);
            var textSource           = new CustomTextSource("Hello World ->");

            using (Start())
            {
                var textLine =
                    TextFormatter.Current.FormatLine(textSource, 0, double.PositiveInfinity, paragraphProperties);

                Assert.Equal(3, textLine.TextRuns.Count);

                Assert.True(textLine.TextRuns[1] is RectangleRun);
            }
        }
Beispiel #4
0
        private void GenerateFormattedText(CustomTextSource textStore, DrawingContext dc, TextFormatter formatter)
        {
            int   textStorePosition = 0;               //Index into the text of the textsource
            Point linePosition      = new Point(0, 0); //current line

            // Format each line of text from the text store and draw it.
            while (textStorePosition < textStore.Text.Length)
            {
                TextLine textLine = formatter.FormatLine(textStore, textStorePosition, textStore.ParagraphWidth, textStore.CTPProperties, null);

                // Draw the formatted text into the drawing context.
                textLine.Draw(dc, linePosition, InvertAxes.None);

                // Update the index position in the text store.
                textStorePosition += textLine.Length;

                // Update the line position coordinate for the displayed line.
                linePosition.Y += textLine.Height;
            }
        }
        protected override Size MeasureOverride(Size availableSize)
        {
            var defaultRunProperties = new GenericTextRunProperties(Typeface.Default, foregroundBrush: Brushes.Black,
                                                                    baselineAlignment: BaselineAlignment.Center);
            var paragraphProperties = new GenericTextParagraphProperties(defaultRunProperties);

            var control = new Button {
                Content = new TextBlock {
                    Text = "ClickMe"
                }
            };

            Content = control;

            var textSource = new CustomTextSource(control, defaultRunProperties);

            control.Measure(Size.Infinity);

            _textLine =
                TextFormatter.Current.FormatLine(textSource, 0, double.PositiveInfinity, paragraphProperties);

            return(base.MeasureOverride(availableSize));
        }
Beispiel #6
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            if (_paragraphProperty == null)
            {
                _paragraphProperty = new FontRendering(
                  48,
                   TextAlignment.Left,
                   null,
                   new Typeface("Arial"),
                   Brushes.Black,
                   Brushes.Transparent,
                   new TextEffectCollection());
            }

            // Initialize the text store.
            if (_textSource == null)
                _textSource = new CustomTextSource();

            _uiLoaded = true;    //All UI is loaded, can handle events now
            UpdateText();
        }