Exemplo n.º 1
0
        void AddExistingOrCreateNewSimpleFontAtlas(
            MultiGlyphSizeBitmapAtlasBuilder multisizeFontAtlasBuilder,
            RequestFont reqFont,
            BitmapFontManager <MemBitmap> bmpFontMx)
        {
            int fontKey = reqFont.GetReqKey();

            string fontTextureFile        = reqFont.Name + "_" + fontKey;
            string resolveFontTextureFile = fontTextureFile + ".info";
            string fontTextureInfoFile    = resolveFontTextureFile;
            string fontTextureImgFilename = fontTextureInfoFile + ".png";

            ResolvedFont resolvedFont = _textServices.ResolveFont(reqFont); //resolve for 'actual' font

            if (PixelFarm.Platforms.StorageService.Provider.DataExists(resolveFontTextureFile) &&
                File.Exists(fontTextureImgFilename))
            {
                multisizeFontAtlasBuilder.AddSimpleAtlasFile(reqFont,
                                                             resolveFontTextureFile,
                                                             fontTextureImgFilename,
                                                             bmpFontMx.TextureKindForNewFont
                                                             );
            }
            else
            {
                //create a new one
                //resolve this font

                SimpleBitmapAtlas fontAtlas = bmpFontMx.GetFontAtlas(resolvedFont, 0, 0, out MemBitmap fontBmp);
                multisizeFontAtlasBuilder.AddSimpleAtlasFile(reqFont,
                                                             resolveFontTextureFile,
                                                             fontTextureImgFilename,
                                                             bmpFontMx.TextureKindForNewFont);
            }
        }
Exemplo n.º 2
0
        void DrawStringToMemBitmap(RequestFont reqFont, string textOutput, float x_pos, float y_pos, int repeatLines = 1)
        {
            ResolvedFont resolvedFont = _textService.ResolveFont(reqFont);

            if (resolvedFont == null)
            {
                //we dont' have
                resolvedFont = _textService.ResolveFont(_defaultReqFont);
                if (resolvedFont == null)
                {
                    throw new NotSupportedException();
                }

                //use alternative typeface, but use reqFont's Size
                resolvedFont = new ResolvedFont(resolvedFont.Typeface, reqFont.SizeInPoints);
            }

            //check if reqFont has alternative or not

            _myAlternativeTypefaceSelector.SetCurrentReqFont(reqFont, _textService);

            PixelFarm.Drawing.VxsTextSpanPrinter _selectedTextPrinter = _devVxsTextPrinter;
            _painter.UseLcdEffectSubPixelRendering = true;
            _painter.FillColor = PixelFarm.Drawing.Color.Black;

            _selectedTextPrinter = _devVxsTextPrinter;

            _selectedTextPrinter.FontSizeInPoints  = resolvedFont.SizeInPoints;
            _selectedTextPrinter.Typeface          = resolvedFont.Typeface;
            _selectedTextPrinter.ScriptLang        = new ScriptLang(ScriptTagDefs.Latin.Tag);
            _selectedTextPrinter.PositionTechnique = PositionTechnique.OpenFont;

            _selectedTextPrinter.HintTechnique  = HintTechnique.None;
            _selectedTextPrinter.EnableLigature = true;
            _selectedTextPrinter.SimulateSlant  = false;

            _selectedTextPrinter.EnableMultiTypefaces = true; //*** for auto typeface selection***

            //_selectedTextPrinter.TextBaseline = PixelFarm.Drawing.TextBaseline.Alphabetic;
            //_selectedTextPrinter.TextBaseline = PixelFarm.Drawing.TextBaseline.Bottom;
            _selectedTextPrinter.TextBaseline = (Typography.Text.TextBaseline)PixelFarm.Drawing.TextBaseline.Top;

            //test print 3 lines
            //#if DEBUG
            //            DynamicOutline.dbugTestNewGridFitting = _contourAnalysisOpts.EnableGridFit;
            //            DynamicOutline.dbugActualPosToConsole = _contourAnalysisOpts.WriteFitOutputToConsole;
            //            DynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment;
            //#endif


            char[] printTextBuffer = textOutput.ToCharArray();


            float lineSpacingPx = _selectedTextPrinter.FontLineSpacingPx;

            const int REF_LINE_LEN = 300;

            for (int i = 0; i < repeatLines; ++i)
            {
                _selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos);
#if DEBUG
                //show debug info...
                var prevColor      = _painter.FillColor;
                var prevStrokColor = _painter.StrokeColor;
                _painter.FillColor = PixelFarm.Drawing.Color.Red;
                _painter.FillRect(x_pos, y_pos, 5, 5); // start point

                //see   //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
                switch (_selectedTextPrinter.TextBaseline)
                {
                default:
                {
                    System.Diagnostics.Debug.WriteLine("UNIMPLEMENTED" + _selectedTextPrinter.TextBaseline.ToString());
                    goto case Typography.Text.TextBaseline.Alphabetic;        //
                }

                case Typography.Text.TextBaseline.Alphabetic:
                {
                    //alphabetic baseline
                    _painter.StrokeColor = _grayColor;
                    _painter.DrawLine(x_pos, /**/ y_pos,
                                      x_pos + REF_LINE_LEN, y_pos);

                    _painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                    _painter.DrawLine(x_pos, /**/ y_pos - _selectedTextPrinter.FontDescedingPx,
                                      x_pos + REF_LINE_LEN, y_pos - _selectedTextPrinter.FontDescedingPx);        //bottom most
                }
                break;

                case Typography.Text.TextBaseline.Top:
                {
                    //alphabetic baseline
                    _painter.StrokeColor = _grayColor;
                    _painter.DrawLine(x_pos, /**/ y_pos + _selectedTextPrinter.FontAscendingPx,
                                      x_pos + REF_LINE_LEN, y_pos + _selectedTextPrinter.FontAscendingPx);
                    //em bottom
                    _painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                    _painter.DrawLine(x_pos, /**/ y_pos + (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx),
                                      x_pos + REF_LINE_LEN, y_pos + (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx));        //bottom most
                }
                break;

                case Typography.Text.TextBaseline.Bottom:
                {
                    //alphabetic baseline
                    _painter.StrokeColor = _grayColor;
                    _painter.DrawLine(x_pos, /**/ y_pos + _selectedTextPrinter.FontDescedingPx,
                                      x_pos + REF_LINE_LEN, y_pos + _selectedTextPrinter.FontDescedingPx);
                    //em bottom
                    _painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                    _painter.DrawLine(x_pos, /**/ y_pos,
                                      x_pos + REF_LINE_LEN, y_pos);        //bottom most
                }
                break;
                }


                _painter.FillColor   = prevColor;
                _painter.StrokeColor = prevColor;
#endif
                y_pos += (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx);
            }

            //reset
            _myAlternativeTypefaceSelector.SetCurrentReqFont(null, null);
        }