Exemplo n.º 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;
            }
        }
Exemplo n.º 2
0
 private static unsafe int SetLineBreakpointsImpl(IntPtr thisPtr, int textPosition, int textLength, IntPtr pLineBreakpoints)
 {
     try
     {
         var shadow = ToShadow<TextAnalysisSinkShadow>(thisPtr);
         var callback = (TextAnalysisSink)shadow.Callback;
         var lineBreakpoints = new LineBreakpoint[textLength];
         Utilities.Read(pLineBreakpoints, lineBreakpoints, 0, textLength);
         callback.SetLineBreakpoints(textPosition, textLength, lineBreakpoints);
     }
     catch (Exception exception)
     {
         return (int)SharpDX.Result.GetResultFromException(exception);
     }
     return Result.Ok.Code;
 }
Exemplo n.º 3
0
 private static unsafe int SetLineBreakpointsImpl(IntPtr thisPtr, int textPosition, int textLength, IntPtr pLineBreakpoints)
 {
     try
     {
         var shadow          = ToShadow <TextAnalysisSinkShadow>(thisPtr);
         var callback        = (TextAnalysisSink)shadow.Callback;
         var lineBreakpoints = new LineBreakpoint[textLength];
         Utilities.Read(pLineBreakpoints, lineBreakpoints, 0, textLength);
         callback.SetLineBreakpoints(textPosition, textLength, lineBreakpoints);
     }
     catch (Exception exception)
     {
         return((int)SharpDX.Result.GetResultFromException(exception));
     }
     return(Result.Ok.Code);
 }
Exemplo n.º 4
0
 public void SetLineBreakpoints(int textPosition, int textLength, LineBreakpoint[] lineBreakpoints)
 {
     if (textLength > 0)
     {
         breakpoints_.AddRange(lineBreakpoints);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        ///   This method applies the results of breakpoint analysis to a range of characters.
        /// </summary>
        /// <param name="textPosition"> This parameter indicates the starting index of the range. </param>
        /// <param name="textLength"> This parameter indicates the length of the range. </param>
        /// <param name="lineBreakpoints"> This parameter contains the results to apply to the range. </param>
        void TextAnalysisSink.SetLineBreakpoints(
			int textPosition, int textLength, DxLineBreakpoint[] lineBreakpoints)
        {
            IndexedRange range = new IndexedRange(textPosition, textLength);

            foreach(int index in range)
            {
                _OutputSink.Characters[index].Breakpoint =
                    new LineBreakpoint(lineBreakpoints[index - textPosition]);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///   This method applies the results of breakpoint analysis to a range of characters.
        /// </summary>
        /// <param name="textPosition"> This parameter indicates the starting index of the range. </param>
        /// <param name="textLength"> This parameter indicates the length of the range. </param>
        /// <param name="lineBreakpoints"> This parameter contains the results to apply to the range. </param>
        void TextAnalysisSink.SetLineBreakpoints(
			int textPosition, int textLength, DxLineBreakpoint[] lineBreakpoints)
        {
            IndexedRange range = new IndexedRange(textPosition, textLength);

            foreach(int index in range)
            {
                var breakpoint = lineBreakpoints[index - textPosition];

                LineBreakCondition beforeCondition = LineBreakCondition.Neutral;

                switch(breakpoint.BreakConditionBefore)
                {
                    case DxBreakCondition.CanBreak:
                        beforeCondition = LineBreakCondition.CanBreak;
                        break;
                    case DxBreakCondition.MayNotBreak:
                        beforeCondition = LineBreakCondition.MayNotBreak;
                        break;
                    case DxBreakCondition.MustBreak:
                        beforeCondition = LineBreakCondition.MustBreak;
                        break;
                    case DxBreakCondition.Neutral:
                        beforeCondition = LineBreakCondition.Neutral;
                        break;
                }

                LineBreakCondition afterCondition = LineBreakCondition.Neutral;

                switch(breakpoint.BreakConditionAfter)
                {
                    case DxBreakCondition.CanBreak:
                        afterCondition = LineBreakCondition.CanBreak;
                        break;
                    case DxBreakCondition.MayNotBreak:
                        afterCondition = LineBreakCondition.MayNotBreak;
                        break;
                    case DxBreakCondition.MustBreak:
                        afterCondition = LineBreakCondition.MustBreak;
                        break;
                    case DxBreakCondition.Neutral:
                        afterCondition = LineBreakCondition.Neutral;
                        break;
                }

                _TextShaper.Characters[index].Breakpoint = new LineBreakpoint(
                    beforeCondition,
                    afterCondition,
                    breakpoint.IsWhitespace,
                    breakpoint.IsSoftHyphen);
            }
        }