public static GlyphTextureBuildDetail[] TryGetGlyphTextureBuildDetail(RequestFont reqFont, bool forAnySize = true, bool forAnyStyle = true) { if (s_registerDetails == null) { SetupDefaults(); } // FontStyle fontStyle = reqFont.Style; float sizeInPt = reqFont.SizeInPoints; if (forAnySize) { sizeInPt = 0; } if (forAnyStyle) { fontStyle = FontStyle.Regular | FontStyle.Bold | FontStyle.Italic; } int fontKey = RequestFont.CalculateFontKey(reqFont.Name.ToLower(), sizeInPt, fontStyle); if (!s_registerDetails.TryGetValue(fontKey, out var found)) { //not found that font key //create default //... return(s_default); } return(found); }
static WinGdiFont SetFont(RequestFont font) { WinGdiFont winFont = WinGdiFontSystem.GetWinGdiFont(font); MyWin32.SelectObject(win32MemDc.DC, winFont.CachedHFont()); return(winFont); }
public void ChangeFont(RequestFont font) { //1. resolve actual font file _reqFont = font; this.Typeface = _textServices.ResolveTypeface(font); //resolve for 'actual' font this.FontSizeInPoints = font.SizeInPoints; }
public ActualFont GetResolvedNativeFont(RequestFont reqFont) { ActualFont found; registerFonts.TryGetValue(reqFont.FontKey, out found); return(found); }
/// <summary> /// Measure the width and height of string <paramref name="str"/> when drawn on device context HDC /// using the given font <paramref name="font"/>.<br/> /// Restrict the width of the string and get the number of characters able to fit in the restriction and /// the width those characters take. /// </summary> /// <param name="str">the string to measure</param> /// <param name="font">the font to measure string with</param> /// <param name="maxWidth">the max width to render the string in</param> /// <param name="charFit">the number of characters that will fit under <see cref="maxWidth"/> restriction</param> /// <param name="charFitWidth"></param> /// <returns>the size of the string</returns> public static PixelFarm.Drawing.Size MeasureString( char[] buff, int startAt, int len, RequestFont font, float maxWidth, out int charFit, out int charFitWidth) { SetFont(font); if (buff.Length == 0) { charFit = 0; charFitWidth = 0; return(PixelFarm.Drawing.Size.Empty); } var size = new Size(); //win32 unsafe { fixed(char *startAddr = &buff[0]) { NativeTextWin32.UnsafeGetTextExtentExPoint( win32MemDc.DC, startAddr + startAt, len, (int)Math.Round(maxWidth), _charFit, _charFitWidth, ref size); } } charFit = _charFit[0]; charFitWidth = charFit > 0 ? _charFitWidth[charFit - 1] : 0; return(new PixelFarm.Drawing.Size(size.W, size.H)); //} }
public static ActualFont GetCacheActualFont(RequestFont r) { ActualFont font; s_actualFonts.TryGetValue(r.FontKey, out font); return(font); }
protected override void OnStart(AppHost host) { Box background_box = new Box(500, 500); background_box.BackColor = PixelFarm.Drawing.Color.Blue; host.AddChild(background_box); //RequestFont font = new RequestFont("Twitter Color Emoji", 20); RequestFont font = new RequestFont("Source Sans Pro", 20); for (int i = 0; i < 1; ++i) { TextFlowLabel label = new TextFlowLabel(300, 50); label.SetLocation(i * 55, i * 55); label.BackColor = PixelFarm.Drawing.Color.Yellow; label.RequestFont = font; //label.Color = PixelFarm.Drawing.Color.Black; //label.Text = "ABC DE FG\r\nHIJ KLM NOP\r\nQRSTUVWXZYZ\r\n0123456789"; //label.Text = "ABCDEFG\r\nHIJKLMNOP\r\nQRSTUVWXZYZ\r\n0123456789"; label.Text = " A 😁😁X 012345"; //label.Text = "😁😁"; //label.Text = "😁"; //label.Text = "A😁"; //label.Text = "A"; host.AddChild(label); } }
public Size MeasureString(char[] buff, int startAt, int len, RequestFont font, float maxWidth, out int charFit, out int charFitWidth) { return(WinGdiTextService.MeasureString(buff, startAt, len, font, maxWidth, out charFit, out charFitWidth)); }
public static Size MeasureString(char[] buff, int startAt, int len, RequestFont font) { //if (_useGdiPlusTextRendering) //{ // ReleaseHdc(); // _characterRanges[0] = new System.Drawing.CharacterRange(0, len); // _stringFormat.SetMeasurableCharacterRanges(_characterRanges); // System.Drawing.Font font2 = (System.Drawing.Font)font.InnerFont; // var size = gx.MeasureCharacterRanges( // new string(buff, startAt, len), // font2, // System.Drawing.RectangleF.Empty, // _stringFormat)[0].GetBounds(gx).Size; // return new PixelFarm.Drawing.Size((int)Math.Round(size.Width), (int)Math.Round(size.Height)); //} //else //{ SetFont(font); PixelFarm.Drawing.Size size = new Size(); if (buff.Length > 0) { unsafe { fixed(char *startAddr = &buff[0]) { NativeTextWin32.UnsafeGetTextExtentPoint32(win32MemDc.DC, startAddr + startAt, len, ref size); } } } return(size); //} }
public void ChangeFont(RequestFont font) { //from request font //we resolve it to actual font this.font = font; this._glyphLayout.ScriptLang = font.GetOpenFontScriptLang(); SimpleFontAtlas foundFontAtlas; ActualFont fontImp = ActiveFontAtlasService.GetTextureFontAtlasOrCreateNew(_fontLoader, font, out foundFontAtlas); if (foundFontAtlas != this.simpleFontAtlas) { //change to another font atlas _glBmp = null; this.simpleFontAtlas = foundFontAtlas; } _typeface = (Typography.OpenFont.Typeface)fontImp.FontFace.GetInternalTypeface(); float srcTextureScale = _typeface.CalculateToPixelScaleFromPointSize(simpleFontAtlas.OriginalFontSizePts); //scale at request float targetTextureScale = _typeface.CalculateToPixelScaleFromPointSize(font.SizeInPoints); _finalTextureScale = targetTextureScale / srcTextureScale; }
/// <summary> /// Measure the width and height of string <paramref name="str"/> when drawn on device context HDC /// using the given font <paramref name="font"/>.<br/> /// Restrict the width of the string and get the number of characters able to fit in the restriction and /// the width those characters take. /// </summary> /// <param name="str">the string to measure</param> /// <param name="font">the font to measure string with</param> /// <param name="maxWidth">the max width to render the string in</param> /// <param name="charFit">the number of characters that will fit under <see cref="maxWidth"/> restriction</param> /// <param name="charFitWidth"></param> /// <returns>the size of the string</returns> public static Size MeasureString(char[] buff, int startAt, int len, RequestFont font, float maxWidth, out int charFit, out int charFitWidth) { //if (_useGdiPlusTextRendering) //{ // ReleaseHdc(); // throw new NotSupportedException("Char fit string measuring is not supported for GDI+ text rendering"); //} //else //{ SetFont(font); if (buff.Length == 0) { charFit = 0; charFitWidth = 0; return(Size.Empty); } var size = new PixelFarm.Drawing.Size(); unsafe { fixed(char *startAddr = &buff[0]) { NativeTextWin32.UnsafeGetTextExtentExPoint( win32MemDc.DC, startAddr + startAt, len, (int)Math.Round(maxWidth), _charFit, _charFitWidth, ref size); } } charFit = _charFit[0]; charFitWidth = charFit > 0 ? _charFitWidth[charFit - 1] : 0; return(size); //} }
Func <PixelFarm.Drawing.GLES2.MyGLDrawBoard> _getDrawboard; // public MyRootGraphic( int width, int height) : base(width, height) { _gfxTimerTaskMx = new GraphicsTimerTaskManager(this); _defaultTextEditFont = MyFontSettings.DefaultRootGraphicsFont; #if DEBUG dbugCurrentGlobalVRoot = this; dbug_Init(null, null, null); #endif //create default render box*** _topWindowRenderBox = new TopWindowRenderBox(this, width, height); _topWindowEventRoot = new TopWindowEventRoot(this, _topWindowRenderBox); _gfxTimerTask = this.SubscribeGraphicsIntervalTask(_normalUpdateTask, TaskIntervalPlan.Animation, 20, (s, e) => { this.PrepareRender(); this.FlushAccumGraphics(); }); _primaryContainerElement = _topWindowRenderBox; }
static int EvaluateFontAndTextColor(DrawBoard d, RunStyle runstyle) { RequestFont font = runstyle.ReqFont; Color color = runstyle.FontColor; RequestFont currentTextFont = d.CurrentFont; Color currentTextColor = d.CurrentTextColor; if (font != null && font != currentTextFont) { if (currentTextColor != color) { return(DIFF_FONT_DIFF_TEXT_COLOR); } else { return(DIFF_FONT_SAME_TEXT_COLOR); } } else { if (currentTextColor != color) { return(SAME_FONT_DIFF_TEXT_COLOR); } else { return(SAME_FONT_SAME_TEXT_COLOR); } } }
public Size MeasureString(char[] str, int startAt, int len, RequestFont font) { int w, h; MeasureString(str, startAt, len, out w, out h); return(new Size(w, h)); }
public override void Init() { //steps : detail ... //1. create a text service (or get it from a singleton class) _textServices = new LayoutFarm.OpenFontTextService(); //2. create manager _bmpFontMx = new BitmapFontManager <MemBitmap>( TextureKind.StencilLcdEffect, _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } ); //3. _font = new RequestFont("tahoma", 10); _fontAtlas = _bmpFontMx.GetFontAtlas(_font, out _fontBmp); //---------- }
void AddExistingOrCreateNewSimpleFontAtlas( MultiGlyphSizeBitmapAtlasBuilder multisizeFontAtlasBuilder, RequestFont reqFont, BitmapFontManager <MemBitmap> bmpFontMx) { int fontKey = reqFont.FontKey; string fontTextureFile = reqFont.Name + "_" + fontKey; string resolveFontTextureFile = fontTextureFile + ".info"; string fontTextureInfoFile = resolveFontTextureFile; string fontTextureImgFilename = fontTextureInfoFile + ".png"; _textServices.ResolveTypeface(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 SimpleBitmapAtlas fontAtlas = bmpFontMx.GetFontAtlas(reqFont, out MemBitmap fontBmp); bmpFontMx.GetFontAtlas(reqFont, out fontBmp); multisizeFontAtlasBuilder.AddSimpleAtlasFile(reqFont, resolveFontTextureFile, fontTextureImgFilename, bmpFontMx.TextureKindForNewFont); } }
public void ChangeFont(RequestFont font) { #if DEBUG //change font Console.Write("please impl change font"); #endif }
public void CalculateGlyphAdvancePos(char[] str, int startAt, int len, RequestFont font, int[] glyphXAdvances) { ////from font ////resolve for typeface //userGlyphPlanList.Clear(); //userCharToGlyphMapList.Clear(); //// //Typeface typeface = typefaceStore.GetTypeface(font.Name, InstalledFontStyle.Normal); //glyphLayout.Typeface = typeface; //glyphLayout.GenerateGlyphPlans(str, startAt, len, userGlyphPlanList, userCharToGlyphMapList); //// //// //float scale = typeface.CalculateToPixelScaleFromPointSize(font.SizeInPoints); //int j = glyphXAdvances.Length; //double actualX = 0; //for (int i = 0; i < j; ++i) //{ // GlyphPlan p = userGlyphPlanList[i]; // double actualAdvX = p.advX * scale; // double newX = actualX + actualAdvX; // glyphXAdvances[i] = (int)Math.Round(newX - actualX); // actualX = newX; //} }
protected override void OnStart(AppHost host) { var listbox = new LayoutFarm.CustomWidgets.ListBox(300, 400); listbox.SetLocation(10, 10); listbox.BackColor = KnownColors.FromKnownColor(KnownColor.LightGray); //add list view to viewport host.AddChild(listbox); //add RequestFont listItemFont = new RequestFont("tahoma", 18); for (int i = 0; i < 10; ++i) { var listItem = new LayoutFarm.CustomWidgets.ListItem(400, 20); if ((i % 2) == 0) { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.OrangeRed); } else { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.Orange); } listItem.SetFont(listItemFont); listItem.Text = "A" + i; listbox.AddItem(listItem); } }
public MyRootGraphic( int width, int height, ITextService ifonts) : base(width, height) { this._ifonts = ifonts; this.graphicTimerTaskMan = new GraphicsTimerTaskManager(this); _defaultTextEditFont = new RequestFont("tahoma", 10); #if DEBUG dbugCurrentGlobalVRoot = this; dbug_Init(null, null, null); #endif //create default render box*** this.topWindowRenderBox = new TopWindowRenderBox(this, width, height); this.topWindowEventRoot = new TopWindowEventRoot(this.topWindowRenderBox); this.SubscribeGraphicsIntervalTask(normalUpdateTask, TaskIntervalPlan.Animation, 20, (s, e) => { this.PrepareRender(); this.FlushAccumGraphics(); }); }
public static void SetLineSpaceHeight(RequestFont reqFont, int platform_id, int height) { reqFont._platform_id = platform_id; reqFont._generalLineSpacingInPx = height; }
public static void SetWhitespaceWidth(RequestFont reqFont, int platform_id, int whitespaceW) { reqFont._platform_id = platform_id; reqFont._whitespace_width = whitespaceW; }
float ITextService.MeasureBlankLineHeight(RequestFont font) { Typeface typeface = ResolveTypeface(font); return((int)(Math.Round(typeface.CalculateMaxLineClipHeight() * typeface.CalculateScaleToPixelFromPointSize(font.SizeInPoints)))); }
// public void CalculateUserCharGlyphAdvancePos(ref TextBufferSpan textBufferSpan, ILineSegmentList lineSegs, RequestFont font, int[] outputUserInputCharAdvance, out int outputTotalW, out int lineHeight) { //layout //from font //resolve for typeface // Typeface typeface = ResolveTypeface(font); _txtServices.SetCurrentFont(typeface, font.SizeInPoints); MyLineSegmentList mylineSegs = (MyLineSegmentList)lineSegs; float scale = typeface.CalculateScaleToPixelFromPointSize(font.SizeInPoints); outputTotalW = 0; int j = mylineSegs.Count; int pos = 0; //start at 0 _reusableTextBuffer.SetRawCharBuffer(textBufferSpan.GetRawCharBuffer()); for (int i = 0; i < j; ++i) { //get each segment MyLineSegment lineSeg = (MyLineSegment)mylineSegs.GetSegment(i); //each line seg may has different script lang _txtServices.CurrentScriptLang = lineSeg.scriptLang; // //CACHING ...., reduce number of GSUB/GPOS // //we cache used line segment for a while //we ask for caching context for a specific typeface and font size GlyphPlanSequence seq = _txtServices.GetUnscaledGlyphPlanSequence(_reusableTextBuffer, lineSeg.StartAt, lineSeg.Length); int seqLen = seq.Count; for (int s = 0; s < seqLen; ++s) { UnscaledGlyphPlan glyphPlan = seq[s]; double actualAdvX = glyphPlan.AdvanceX; outputTotalW += outputUserInputCharAdvance[pos + glyphPlan.input_cp_offset] += (int)Math.Round(actualAdvX * scale); } pos += lineSeg.Length; } // lineHeight = (int)Math.Round(typeface.CalculateRecommendLineSpacing() * scale); _reusableTextBuffer.SetRawCharBuffer(null); }
/// <summary> /// get from cache or create a new one /// </summary> /// <param name="reqFont"></param> /// <returns></returns> public SimpleFontAtlas GetFontAtlas(RequestFont reqFont, out GLBitmap glBmp) { int fontKey = reqFont.FontKey; SimpleFontAtlas fontAtlas; if (!_createdAtlases.TryGetValue(fontKey, out fontAtlas)) { Typeface resolvedTypeface = textServices.ResolveTypeface(reqFont); //if we don't have //the create it SimpleFontAtlasBuilder atlasBuilder = null; var textureGen = new GlyphTextureBitmapGenerator(); textureGen.CreateTextureFontFromScriptLangs( resolvedTypeface, reqFont.SizeInPoints, _textureKind, _currentScriptLangs, (glyphIndex, glyphImage, outputAtlasBuilder) => { if (outputAtlasBuilder != null) { //finish atlasBuilder = outputAtlasBuilder; } } ); GlyphImage totalGlyphsImg = atlasBuilder.BuildSingleImage(); //create atlas fontAtlas = atlasBuilder.CreateSimpleFontAtlas(); fontAtlas.TotalGlyph = totalGlyphsImg; #if DEBUG //save glyph image for debug //PixelFarm.Agg.ActualImage.SaveImgBufferToPngFile( // totalGlyphsImg.GetImageBuffer(), // totalGlyphsImg.Width * 4, // totalGlyphsImg.Width, totalGlyphsImg.Height, // "d:\\WImageTest\\total_" + reqFont.Name + "_" + reqFont.SizeInPoints + ".png"); #endif //cache the atlas _createdAtlases.Add(fontKey, fontAtlas); // //calculate some commonly used values fontAtlas.SetTextureScaleInfo( resolvedTypeface.CalculateScaleToPixelFromPointSize(fontAtlas.OriginalFontSizePts), resolvedTypeface.CalculateScaleToPixelFromPointSize(reqFont.SizeInPoints)); //TODO: review here, use scaled or unscaled values fontAtlas.SetCommonFontMetricValues( resolvedTypeface.Ascender, resolvedTypeface.Descender, resolvedTypeface.LineGap, resolvedTypeface.CalculateRecommendLineSpacing()); } glBmp = _loadedGlyphs.GetOrCreateNewOne(fontAtlas); return(fontAtlas); }
public override void SetFont(RequestFont font) { _font = font; if (_myTextRun != null) { _myTextRun.RequestFont = font; } }
public static void SetActualFont(RequestFont reqFont, int platform_id, object platformFont) { //replace reqFont._platform_id = platform_id; reqFont._latestResolved = new WeakReference(platformFont); }
public GLPainter() { CurrentFont = new RequestFont("tahoma", 14); UseVertexBufferObjectForRenderVx = true; //tools _pathRenderVxBuilder = PathRenderVxBuilder.CreateNew(); _defaultBrush = _currentBrush = new SolidBrush(Color.Black); //default brush }
float ITextService.MeasureBlankLineHeight(RequestFont font) { LineSpacingChoice sel_linespcingChoice; Typeface typeface = ResolveTypeface(font); return((int)(Math.Round(typeface.CalculateRecommendLineSpacing(out sel_linespcingChoice) * typeface.CalculateScaleToPixelFromPointSize(font.SizeInPoints)))); }
public Size MeasureString(ref TextBufferSpan textBufferSpan, RequestFont font) { Typeface typeface = ResolveTypeface(font); _txtServices.SetCurrentFont(typeface, font.SizeInPoints); _txtServices.MeasureString(textBufferSpan.GetRawCharBuffer(), textBufferSpan.start, textBufferSpan.len, out int w, out int h); return(new Size(w, h)); }
public ActualFont ResolveForTextureFont(RequestFont font) { //check if we have texture font fot this font TextureFont t = TextureFont.GetCacheFontAsTextureFont(font); if (t != null) { return t; } //-------------------------------------------------------------------- LateTextureFontInfo lateFontInfo; if (!textureBitmapInfos.TryGetValue(font.Name, out lateFontInfo)) { //not found return null; } //check if we have create TextureFont TextureFontFace textureFontface = lateFontInfo.Fontface; if (textureFontface == null) { //load glyh image here GlyphImage glyphImage = null; using (var nativeImg = new PixelFarm.Drawing.Imaging.NativeImage(lateFontInfo.TextureBitmapFile)) { glyphImage = new GlyphImage(nativeImg.Width, nativeImg.Height); var buffer = new int[nativeImg.Width * nativeImg.Height]; System.Runtime.InteropServices.Marshal.Copy(nativeImg.GetNativeImageHandle(), buffer, 0, buffer.Length); glyphImage.SetImageBuffer(buffer, true); } InstalledFont installedFont = GLES2PlatformFontMx.GetInstalledFont(font.Name, InstalledFontStyle.Regular); FontFace nOpenTypeFontFace = NOpenTypeFontLoader.LoadFont(installedFont.FontPath, GLES2PlatformFontMx.defaultLang, GLES2PlatformFontMx.defaultHbDirection, GLES2PlatformFontMx.defaultScriptCode); textureFontface = new TextureFontFace(nOpenTypeFontFace, lateFontInfo.FontMapFile, glyphImage); lateFontInfo.Fontface = textureFontface; return textureFontface.GetFontAtPointsSize(font.SizeInPoints); } if (textureFontface != null) { t = (TextureFont)(textureFontface.GetFontAtPointsSize(font.SizeInPoints)); t.AssignToRequestFont(font); return t; } else { // //need to create font face //create fontface first } return null; }
///////////////////////////////////////// // public ActualFont ResolveForGdiFont(RequestFont font) { return null; }
public ActualFont GetResolvedNativeFont(RequestFont reqFont) { ActualFont found; registerFonts.TryGetValue(reqFont.FontKey, out found); return found; }
public abstract Size MeasureStringImpl(char[] buff, int startAt, int len, RequestFont font);
public abstract Size MeasureStringImpl(char[] buff, int startAt, int len, RequestFont font, float maxWidth, out int charFit, out int charFitWidth);
protected static void SetCacheActualFont(RequestFont r, ActualFont a) { RequestFont.SetCacheActualFont(r, a); }
//--------------------- protected static ActualFont GetCacheActualFont(RequestFont r) { return RequestFont.GetCacheActualFont(r); }