void LayoutWithoutHorizontalFitAlign(IGlyphPositions posStream, List <GlyphPlan> outputGlyphPlanList)
        {
            //the default OpenFont layout without fit-to-writing alignment
            int    finalGlyphCount = posStream.Count;
            float  pxscale         = _typeface.CalculateToPixelScaleFromPointSize(this._fontSizeInPoints);
            double cx = 0;
            short  cy = 0;

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

                float s_advW  = advW * pxscale;
                float exact_x = (float)(cx + offsetX * pxscale);
                float exact_y = (float)(cy + offsetY * pxscale);

                outputGlyphPlanList.Add(new GlyphPlan(
                                            glyphIndex,
                                            exact_x,
                                            exact_y,
                                            advW));
                cx += s_advW;
            }
        }
Пример #2
0
 protected override void OnFontSizeChanged()
 {
     //update some font matrix property
     if (_currentTypeface != null)
     {
         float pointToPixelScale = _currentTypeface.CalculateToPixelScaleFromPointSize(this.FontSizeInPoints);
         this.FontAscendingPx   = _currentTypeface.Ascender * pointToPixelScale;
         this.FontDescedingPx   = _currentTypeface.Descender * pointToPixelScale;
         this.FontLineGapPx     = _currentTypeface.LineGap * pointToPixelScale;
         this.FontLineSpacingPx = FontAscendingPx - FontDescedingPx + FontLineGapPx;
     }
 }
        public static double GetLineHeight(string fontFamily, double fontSize)
        {
            Typeface typeFace = GetTypeFace(fontFamily);
            var      scale    = typeFace.CalculateToPixelScaleFromPointSize((float)fontSize);

            return((typeFace.Ascender - typeFace.Descender + typeFace.LineGap) * scale);
        }
        public static float GetScale(string fontFamily, double fontSize)
        {
            Typeface typeFace = GetTypeFace(fontFamily);
            var      scale    = typeFace.CalculateToPixelScaleFromPointSize((float)fontSize);

            return(scale);
        }
        /// <summary>
        /// get glyph mesh from current font setting
        /// </summary>
        /// <param name="glyphIndex"></param>
        /// <returns></returns>
        public VertexStore GetGlyphMesh(ushort glyphIndex)
        {
            GlyphMeshData glyphMeshData = InternalGetGlyphMesh(glyphIndex);

            if (glyphMeshData.vxsStore == null)
            {
                //build vxs
                _tovxs.Reset();
                float pxscale = _currentTypeface.CalculateToPixelScaleFromPointSize(_currentFontSizeInPoints);
                GlyphDynamicOutline dynamicOutline = glyphMeshData.dynamicOutline;
                if (dynamicOutline != null)
                {
                    dynamicOutline.GenerateOutput(_tovxs, pxscale);
                    glyphMeshData.vxsStore = new VertexStore();
                    _tovxs.WriteOutput(glyphMeshData.vxsStore, _vxsPool);
                }
                else
                {
                    //no dynamic outline
                    glyphMeshData.vxsStore = new VertexStore();
                    _currentGlyphBuilder.ReadShapes(_tovxs);
                    //TODO: review here,
                    //float pxScale = _glyphPathBuilder.GetPixelScale();
                    _tovxs.WriteOutput(glyphMeshData.vxsStore, _vxsPool);
                }
            }
            return(glyphMeshData.vxsStore);
        }
Пример #6
0
 public NOpenFont(NOpenFontFace ownerFace, float sizeInPoints, FontStyle style)
 {
     this.ownerFace    = ownerFace;
     this.sizeInPoints = sizeInPoints;
     this.style        = style;
     this.typeFace     = ownerFace.Typeface;
     //calculate scale ***
     scale = typeFace.CalculateToPixelScaleFromPointSize(sizeInPoints);
 }
Пример #7
0
        public void DrawString(RenderVxFormattedString renderVx, double x, double y)
        {
            float ox = canvasPainter.OriginX;
            float oy = canvasPainter.OriginY;

            //1. update some props..
            //2. update current type face
            UpdateTypefaceAndGlyphBuilder();
            _glyphMeshStore.SetFont(_currentTypeface, this.FontSizeInPoints);
            //3. layout glyphs with selected layout technique
            //TODO: review this again, we should use pixel?
            float fontSizePoint = this.FontSizeInPoints;
            float scale         = _currentTypeface.CalculateToPixelScaleFromPointSize(fontSizePoint);

            RenderVxGlyphPlan[] glyphPlans = renderVx.glyphList;
            int j = glyphPlans.Length;
            //---------------------------------------------------
            //consider use cached glyph, to increase performance

            //GlyphPosPixelSnapKind x_snap = this.GlyphPosPixelSnapX;
            //GlyphPosPixelSnapKind y_snap = this.GlyphPosPixelSnapY;
            float g_x   = 0;
            float g_y   = 0;
            float baseY = (int)y;

            for (int i = 0; i < j; ++i)
            {
                RenderVxGlyphPlan glyphPlan = glyphPlans[i];
                //-----------------------------------
                //TODO: review here ***
                //PERFORMANCE revisit here
                //if we have create a vxs we can cache it for later use?
                //-----------------------------------
                VertexStore vxs = _glyphMeshStore.GetGlyphMesh(glyphPlan.glyphIndex);
                g_x = (float)(glyphPlan.x * scale + x);
                g_y = (float)glyphPlan.y * scale;

                canvasPainter.SetOrigin(g_x, g_y);
                canvasPainter.Fill(vxs);
            }
            //restore prev origin
            canvasPainter.SetOrigin(ox, oy);
        }
Пример #8
0
        public void DrawString(char[] text, int startAt, int len, double x, double y)
        {
            float ox = canvasPainter.OriginX;
            float oy = canvasPainter.OriginY;

            //1. update some props..
            //2. update current type face
            UpdateTypefaceAndGlyphBuilder();
            Typeface typeface = _glyphPathBuilder.Typeface;
            //3. layout glyphs with selected layout technique
            //TODO: review this again, we should use pixel?

            float fontSizePoint = this.FontSizeInPoints;
            float scale         = typeface.CalculateToPixelScaleFromPointSize(fontSizePoint);

            _outputGlyphPlans.Clear();
            _glyphLayout.Layout(typeface, text, startAt, len, _outputGlyphPlans);
            //4. render each glyph
            int j = _outputGlyphPlans.Count;

            //---------------------------------------------------
            //consider use cached glyph, to increase performance
            hintGlyphCollection.SetCacheInfo(typeface, fontSizePoint, this.HintTechnique);
            //---------------------------------------------------
            for (int i = 0; i < j; ++i)
            {
                GlyphPlan glyphPlan = _outputGlyphPlans[i];
                //-----------------------------------
                //TODO: review here ***
                //PERFORMANCE revisit here
                //if we have create a vxs we can cache it for later use?
                //-----------------------------------
                VertexStore glyphVxs;
                if (!hintGlyphCollection.TryGetCacheGlyph(glyphPlan.glyphIndex, out glyphVxs))
                {
                    //if not found then create new glyph vxs and cache it
                    _glyphPathBuilder.SetHintTechnique(this.HintTechnique);
                    _glyphPathBuilder.BuildFromGlyphIndex(glyphPlan.glyphIndex, fontSizePoint);
                    //-----------------------------------
                    _tovxs.Reset();
                    _glyphPathBuilder.ReadShapes(_tovxs);

                    //TODO: review here,
                    //float pxScale = _glyphPathBuilder.GetPixelScale();
                    glyphVxs = new VertexStore();
                    _tovxs.WriteOutput(glyphVxs, _vxsPool);
                    //
                    hintGlyphCollection.RegisterCachedGlyph(glyphPlan.glyphIndex, glyphVxs);
                }
                canvasPainter.SetOrigin((float)(glyphPlan.x * scale + x), (float)(glyphPlan.y * scale + y));
                canvasPainter.Fill(glyphVxs);
            }
            //restore prev origin
            canvasPainter.SetOrigin(ox, oy);
        }
Пример #9
0
        public Size MeasureString(char[] str, int startAt, int len, RequestFont font)
        {
            //resolve type face
            Typeface typeface = typefaceStore.GetTypeface(font.Name, InstalledFontStyle.Normal);

            glyphLayout.Typeface = typeface;
            MeasuredStringBox result;
            float             scale = typeface.CalculateToPixelScaleFromPointSize(font.SizeInPoints);

            //measure string at specific px scale
            glyphLayout.MeasureString(str, startAt, len, out result, scale);

            return(new Size((int)result.width, (int)result.CalculateLineHeight()));
        }
Пример #10
0
        public void PrepareStringForRenderVx(RenderVxFormattedString renderVx, char[] text, int startAt, int len)
        {
            //1. update some props..
            //2. update current type face
            UpdateTypefaceAndGlyphBuilder();
            Typeface typeface = _currentTypeface;// _glyphPathBuilder.Typeface;
            //3. layout glyphs with selected layout technique
            //TODO: review this again, we should use pixel?

            float pxscale = typeface.CalculateToPixelScaleFromPointSize(FontSizeInPoints);

            _outputGlyphPlans.Clear();
            _glyphLayout.Layout(typeface, text, startAt, len, _outputGlyphPlans);
            TextPrinterHelper.CopyGlyphPlans(renderVx, _outputGlyphPlans, pxscale);
        }
Пример #11
0
 public override float GetScale(float pointSize)
 {
     return(typeface.CalculateToPixelScaleFromPointSize(pointSize));
 }
Пример #12
0
        public void RenderChar(char testChar, HintTechnique hint)
        {
            builder.SetHintTechnique(hint);
#if DEBUG
            GlyphBoneJoint.dbugTotalId        = 0;//reset
            builder.dbugAlwaysDoCurveAnalysis = true;
#endif
            _infoView.Clear();
            _latestHint = hint;
            _testChar   = testChar;
            //----------------------------------------------------
            //
            builder.Build(testChar, _sizeInPoint);
            var txToVxs1 = new GlyphTranslatorToVxs();
            builder.GlyphDynamicEdgeOffset = this.GlyphEdgeOffset;

            builder.ReadShapes(txToVxs1);

#if DEBUG
            var ps = txToVxs1.dbugGetPathWriter();
            _infoView.ShowOrgBorderInfo(ps.Vxs);
#endif
            VertexStore vxs = new VertexStore();

            txToVxs1.WriteOutput(vxs, _vxsPool);
            //----------------------------------------------------

            //----------------------------------------------------
            painter.UseSubPixelRendering = this.UseLcdTechnique;
            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            painter.Clear(PixelFarm.Drawing.Color.White);

            RectD bounds = new RectD();
            BoundingRect.GetBoundingRect(new VertexStoreSnap(vxs), ref bounds);
            //----------------------------------------------------
            float scale = _typeface.CalculateToPixelScaleFromPointSize(_sizeInPoint);
            _pxscale = scale;
            this._infoView.PxScale = scale;


            var   left2   = 0;
            int   floor_1 = (int)left2;
            float diff    = left2 - floor_1;
            //----------------------------------------------------
            if (OffsetMinorX)
            {
                MinorOffsetInfo = left2.ToString() + " =>" + floor_1 + ",diff=" + diff;
            }
            else
            {
                MinorOffsetInfo = left2.ToString();
            }


            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            painter.Clear(PixelFarm.Drawing.Color.White);

            if (FillBackGround)
            {
                //5.2
                painter.FillColor = PixelFarm.Drawing.Color.Black;

                float xpos = 5;// - diff;
                if (OffsetMinorX)
                {
                    xpos -= diff;
                }

                painter.SetOrigin(xpos, 10);
                painter.Fill(vxs);
            }
            if (DrawBorder)
            {
                //5.4
                painter.StrokeColor = PixelFarm.Drawing.Color.Green;
                //user can specific border width here...
                //5.5
                painter.Draw(vxs);
                //--------------
                int    markOnVertexNo = _infoView.DebugMarkVertexCommand;
                double x, y;
                vxs.GetVertex(markOnVertexNo, out x, out y);
                painter.FillRectLBWH(x, y, 4, 4, PixelFarm.Drawing.Color.Red);
                //--------------
                _infoView.ShowFlatternBorderInfo(vxs);
                //--------------
            }
#if DEBUG
            builder.dbugAlwaysDoCurveAnalysis = false;
#endif

            if (ShowTess)
            {
                RenderTessTesult();
            }

            //if (DrawDynamicOutline)
            //{
            //    GlyphDynamicOutline dynamicOutline = builder.LatestGlyphFitOutline;
            //    WalkDynamicOutline(painter, dynamicOutline, scale, DrawRegenerateOutline);

            //}
        }
Пример #13
0
 public float CalculateToPixelScaleFromPointSize(float sizeInPoint)
 {
     return(typeface.CalculateToPixelScaleFromPointSize(sizeInPoint));
 }