Beispiel #1
0
        /// <summary>
        /// Analyzes the text using each of the analyzers and returns
        /// their results as a series of runs.
        /// </summary>
        public void GenerateResults(TextAnalyzer textAnalyzer, out Run[] runs, out LineBreakpoint[] breakpoints)
        {
            // Initially start out with one result that covers the entire range.
            // This result will be subdivided by the analysis processes.
            LinkedRun initialRun = new LinkedRun()
            {
                nextRunIndex = 0,
                textStart    = 0,
                textLength   = text_.Length,
                bidiLevel    = (readingDirection_ == ReadingDirection.RightToLeft) ? 1 : 0
            };

            runs_ = new List <LinkedRun>();
            runs_.Add(initialRun);

            breakpoints_ = new List <LineBreakpoint>();

            textAnalyzer.AnalyzeLineBreakpoints(this, 0, text_.Length, this);
            textAnalyzer.AnalyzeBidi(this, 0, text_.Length, this);
            textAnalyzer.AnalyzeScript(this, 0, text_.Length, this);
            textAnalyzer.AnalyzeNumberSubstitution(this, 0, text_.Length, this);
            //Call each of the analyzers in sequence, recording their results.
            breakpoints = new LineBreakpoint[breakpoints_.Count];
            breakpoints_.CopyTo(breakpoints);

            // Resequence the resulting runs in order before returning to caller.
            runs = new Run[runs_.Count];
            int nextRunIndex = 0;

            for (int i = 0; i < runs_.Count; i++)
            {
                runs[i]      = runs_[nextRunIndex].AsRun;
                nextRunIndex = runs_[nextRunIndex].nextRunIndex;
            }
        }
Beispiel #2
0
        protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory)
        {
            base.OnCreateDeviceIndependentResources(factory);
            _textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", 72);
            _textFormat.TextAlignment      = TextAlignment.Center;
            _textFormat.ParagraphAlignment = ParagraphAlignment.Center;
            float width  = ClientSize.Width / dpiScaleX;
            float height = ClientSize.Height / dpiScaleY;

            _textLayout   = DirectWriteFactory.CreateTextLayout("Click on this text Click on this text", _textFormat, width, height);
            _textAnalyzer = DirectWriteFactory.CreateTextAnalyzer();
            _source       = new MyTextSource("Click on this text Click on this text");
            using (FontCollection coll = _textFormat.FontCollection)
            {
                int count = coll.Count;
                for (int index = 0; index < count; ++index)
                {
                    using (FontFamily ff = coll[index])
                    {
                        using (Font font = ff.GetFirstMatchingFont(FontWeight.Normal, FontStretch.Normal, FontStyle.Normal))
                        {
                            LocalizedStrings ls   = font.FaceNames;
                            LocalizedStrings desc = font.GetInformationalStrings(InformationalStringId.Designer);

                            int cultureIndex = ls.FindCulture(CultureInfo.CurrentCulture);
                            if (cultureIndex >= 0)
                            {
                                string      faceName = ls[cultureIndex];
                                FontMetrics metrics  = font.Metrics;
                            }
                        }
                    }
                }
            }
            _textAnalyzer.AnalyzeLineBreakpoints(_source, 0, (uint)_source.Text.Length);
            _textAnalyzer.AnalyzeScript(_source, 0, (uint)_source.Text.Length);
        }