Пример #1
0
        public float CalculateWidth()
        {
            GlyphPlanList plans = glyphBuffer;
            int           end   = startAt + len;
            float         width = 0;

            for (int i = startAt; i < end; ++i)
            {
                width += plans[i].AdvanceX;
            }
            return(width);
        }
Пример #2
0
        public float CalculateWidth()
        {
            GlyphPlanList plans = UnsafeGetInteralGlyphPlanList(this);
            int           end   = startAt + len;
            float         width = 0;

            for (int i = startAt; i < end; ++i)
            {
                width += plans[i].AdvanceX;
            }
            return(width);
        }
Пример #3
0
        /// <summary>
        /// generate scaled from unscale glyph size to specific scale
        /// </summary>
        /// <param name="glyphPositions"></param>
        /// <param name="pxscale"></param>
        /// <param name="outputGlyphPlanList"></param>
        public static void GenerateGlyphPlans(IGlyphPositions glyphPositions,
                                              float pxscale,
                                              bool snapToGrid,
                                              GlyphPlanList outputGlyphPlanList)
        {
            //user can implement this with some 'PixelScaleEngine'

            //double cx = 0;
            //short cy = 0;
            //the default OpenFont layout without fit-to-writing alignment
            int    finalGlyphCount = glyphPositions.Count;
            double cx = 0;
            short  cy = 0;

            for (int i = 0; i < finalGlyphCount; ++i)
            {
                short  input_offset, offsetX, offsetY, advW; //all from pen-pos
                ushort glyphIndex = glyphPositions.GetGlyph(i, out input_offset, out offsetX, out offsetY, out advW);

                float s_advW = advW * pxscale;

                if (snapToGrid)
                {
                    //TEST,
                    //if you want to snap each glyph to grid (1px or 0.5px) by ROUNDING
                    //we can do it here,this produces a predictable caret position result
                    //
                    s_advW += (int)Math.Round(s_advW);
                }
                float exact_x = (float)(cx + offsetX * pxscale);
                float exact_y = (float)(cy + offsetY * pxscale);

                outputGlyphPlanList.Append(new GlyphPlan(
                                               input_offset,
                                               glyphIndex,
                                               exact_x,
                                               exact_y,
                                               advW));
                cx += s_advW;
            }
        }
Пример #4
0
 internal GlyphPlanSequence(GlyphPlanList glyphBuffer, int startAt, int len)
 {
     this.glyphBuffer = glyphBuffer;
     this.startAt     = startAt;
     this.len         = (ushort)len;
 }
        public void DoLayout()
        {
            //user can use other native methods
            //to do the layout ***

            //the following code is how-to-layout with
            //our Typography lib
            //

            //then at this step
            //we calculate span size
            //resolve each font style


            _glyphLayout.EnableComposition = true;
            _glyphLayout.EnableLigature    = true;

            int lineCount = _lines.Count;

            GlyphPlanList   outputGlyphPlan  = new GlyphPlanList();
            GlyphPlanBuffer glyphPlanBuffer  = new GlyphPlanBuffer(outputGlyphPlan);
            Typeface        selectedTypeface = this.DefaultTypeface;


            //
            float pxscale = selectedTypeface.CalculateScaleToPixelFromPointSize(this.FontSizeInPts);


            for (int i = 0; i < lineCount; ++i)
            {
                EditableTextLine line    = _lines[i];
                List <IRun>      runList = line.UnsageGetTextRunList();
                int runCount             = runList.Count;

                for (int r = 0; r < runCount; ++r)
                {
                    TextRun tt = runList[r] as TextRun;
                    if (tt == null)
                    {
                        continue;
                    }
                    //this is text run
                    if (tt.IsMeasured)
                    {
                        continue;
                    }
                    //

                    TextRunFontStyle fontStyle = tt.FontStyle;
                    //resolve to actual font face
                    TextBuffer buffer    = tt.TextBuffer;
                    char[]     rawBuffer = buffer.UnsafeGetInternalBuffer();

                    int preCount = outputGlyphPlan.Count;
                    _glyphLayout.Typeface = selectedTypeface;
                    _glyphLayout.Layout(rawBuffer, tt.StartAt, tt.Len);

                    //use pixel-scale-layout-engine to scale to specific font size
                    //or scale it manually

                    int postCount = outputGlyphPlan.Count;


                    //
                    tt.SetGlyphPlanSeq(new GlyphPlanSequence(glyphPlanBuffer, preCount, postCount - preCount));
                    tt.IsMeasured = true;
                    //
                }
            }
        }
Пример #6
0
 public GlyphPlanBuffer(GlyphPlanList glyphPlans)
 {
     this._glyphPlans = glyphPlans;
 }