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 MyRootGraphic(UIPlatform uiPlatform, int width, int height) : base(width, height) { this.uiPlatform = uiPlatform; this.graphicTimerTaskMan = new GraphicsTimerTaskManager(this, uiPlatform); _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(); }); }
protected override void OnStart(AppHost host) { Box background_box = new Box(250, 500); background_box.BackColor = PixelFarm.Drawing.Color.White; host.AddChild(background_box); //PixelFarm.Drawing.RequestFont font = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 20); var font = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 20); { Label label = new Label(); label.TextColor = PixelFarm.Drawing.Color.Black; label.SetLocation(10, 20); label.SetFont(font); label.Text = "XY"; host.AddChild(label); } { Label label = new Label(); label.TextColor = PixelFarm.Drawing.Color.Black; label.SetFont(font); label.Text = "A12345"; label.SetLocation(30, 20); host.AddChild(label); } }
Size CalculateDrawingStringSize(int length) { if (!_content_unparsed) { //the content is parsed *** if (this.mybuffer.Length == length) { return(this.Size); } else { //ca int total = 0; if (outputUserCharAdvances != null) { for (int i = 0; i < length; ++i) { total += this.outputUserCharAdvances[i]; } } return(new Size(total, (int)Math.Round(Root.TextServices.MeasureBlankLineHeight(GetFont())))); } } PixelFarm.Drawing.RequestFont fontInfo = GetFont(); var textBufferSpan = new TextBufferSpan(this.mybuffer, 0, length); return(this.Root.TextServices.MeasureString(ref textBufferSpan, fontInfo)); }
protected override void OnPainterReady(Painter painter) { _font1 = new PixelFarm.Drawing.RequestFont("tahoma", 11); _font2 = new PixelFarm.Drawing.RequestFont("tahoma", 16); painter.UseLcdEffectSubPixelRendering = true; painter.CurrentFont = _font1; //-------------- }
protected override void OnPainterReady(Painter painter) { _font1 = new PixelFarm.Drawing.RequestFont("tahoma", 15); _font2 = new PixelFarm.Drawing.RequestFont("tahoma", 11); painter.UseSubPixelLcdEffect = true; painter.CurrentFont = _font1; }
SmoothingMode _smoothingMode; //smoothing mode of this painter public GLCanvasPainterBase(CanvasGL2d canvas, int w, int h) { _canvas = canvas; _width = w; _height = h; _rectInt = new RectInt(0, 0, w, h); arcTool = new Arc(); CurrentFont = new RequestFont("tahoma", 14); }
protected override void OnReadyForInitGLShaderProgram() { //just an example //this is slow on init. //since we must wait until msdf texture generation is complete. //in real-world, we should use caching. using (System.IO.FileStream fs = new System.IO.FileStream("Samples\\SourceSansPro-Regular.ttf", System.IO.FileMode.Open)) { _typeface = new OpenFontReader().Read(fs); } var reqFont = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 32); //1. create glyph-texture-bitmap generator var glyphTextureGen = new GlyphTextureBitmapGenerator(); glyphTextureGen.MsdfGenVersion = 3; //2. generate the glyphs var atlasBuilder = new SimpleBitmapAtlasBuilder(); glyphTextureGen.CreateTextureFontFromBuildDetail( atlasBuilder, _typeface, reqFont.SizeInPoints, TextureKind.Msdf, GlyphTextureCustomConfigs.TryGetGlyphTextureBuildDetail( Typography.Text.GlobalTextService.TxtClient.ResolveFont(reqFont), false, false) ); //3. set information before write to font-info atlasBuilder.SpaceCompactOption = SimpleBitmapAtlasBuilder.CompactOption.ArrangeByHeight; //4. merge all glyph in the builder into a single image PixelFarm.CpuBlit.MemBitmap totalGlyphsImg = atlasBuilder.BuildSingleImage(true); //------------------------------------------------------------- //5. create a simple font atlas from information inside this atlas builder. _fontAtlas = atlasBuilder.CreateSimpleBitmapAtlas(); _fontAtlas.SetMainBitmap(totalGlyphsImg, true); byte[] codepoint = System.Text.Encoding.UTF8.GetBytes("AB"); _glyphIndex_0 = _typeface.GetGlyphIndex(codepoint[0]); _glyphIndex_1 = _typeface.GetGlyphIndex(codepoint[1]); }
protected override void OnStart(AppHost host) { Box background_box = new Box(250, 500); background_box.BackColor = PixelFarm.Drawing.Color.Blue; host.AddChild(background_box); //PixelFarm.Drawing.RequestFont font = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 20); PixelFarm.Drawing.RequestFont font = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 20); for (int i = 0; i < 10; ++i) { Label label = new Label(); label.SetLocation(i * 20, i * 20); label.TextColor = PixelFarm.Drawing.Color.Black; label.SetFont(font); label.Text = "Lpppyf ABCDEFG HI0123 456789 ABD"; host.AddChild(label); } }
internal float MeasureStringWidth(char[] buffer, int startIndex, int len, RequestFont f) { return this.SampleIFonts.MeasureString(buffer, startIndex, len, f).Width; }
//--------------------- protected static ActualFont GetCacheActualFont(RequestFont r) { //throw new NotSupportedException(); //return RequestFont.GetCacheActualFont(r); return(CacheFont.GetCacheActualFont(r)); }
internal static void SetCacheActualFont(RequestFont r, ActualFont f) { r._actualFont = f; }
public TextureFont GetResolvedFont(RequestFont f) { TextureFont found; registerFonts.TryGetValue(f.FontKey, out found); return found; }
internal static ActualFont GetCacheActualFont(RequestFont r) { return r._actualFont; }
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 static void SetCacheActualFont(RequestFont r, ActualFont a) { s_actualFonts[r.GetReqKey()] = a; }
public static float MeasureWhitespace(RequestFont f) { return whitespaceSize = MeasureString(whitespace, 0, 1, f).Width; }
static WinGdiFont SetFont(RequestFont font) { WinGdiFont winFont = WinGdiFontSystem.GetWinGdiFont(font); MyWin32.SelectObject(win32MemDc.DC, winFont.ToHfont()); return winFont; }
public static WinGdiFont GetWinGdiFont(RequestFont f) { if (f == null) { throw new NotSupportedException(); } if (f == latestFont) { return latestWinFont; } WinGdiFont actualFontInside = WinGdiFont.GetCacheFontAsWinGdiFont(f); if (actualFontInside != null) { return actualFontInside; } //----- //need to create a new one //get register font or create the new one FontKey key = f.FontKey; WinGdiFont found; if (!registerFonts.TryGetValue(key, out found)) { //create the new one and register //create fontface FontFaceKey fontfaceKey = new FontFaceKey(key); WinGdiFontFace fontface; if (!winGdiFonFaces.TryGetValue(fontfaceKey, out fontface)) { //create new fontface = new WinGdiFontFace(f.Name, f.Style); winGdiFonFaces.Add(fontfaceKey, fontface); } found = (WinGdiFont)fontface.GetFontAtPointsSize(f.SizeInPoints); registerFonts.Add(key, found);//cache here } latestFont = f; found.AssignToRequestFont(f); return latestWinFont = found; }
public static WinGdiFont GetCacheFontAsWinGdiFont(RequestFont r) { return GetCacheActualFont(r) as WinGdiFont; }
internal Size MeasureStringSize(char[] buffer, int startIndex, int len, RequestFont f) { return this.SampleIFonts.MeasureString(buffer, startIndex, len, f); }
protected static void SetCacheActualFont(RequestFont r, ActualFont a) { CacheFont.SetCacheActualFont(r, a); //throw new NotSupportedException(); //RequestFont.SetCacheActualFont(r, a); }
/// <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; //} }
public static ActualFont GetCacheActualFont(RequestFont r) { s_actualFonts.TryGetValue(r.GetReqKey(), out ActualFont font); return(font); }
public float MeasureWhitespace(RequestFont f) { return WinGdiTextService.MeasureWhitespace(f); }
public void RegisterFont(RequestFont f, TextureFont textureFont) { registerFonts.Add(f.FontKey, textureFont); }
public void CalculateGlyphAdvancePos(char[] str, int startAt, int len, RequestFont font, int[] glyphXAdvances) { WinGdiTextService.CalculateGlyphAdvancePos(str, startAt, len, font, glyphXAdvances); }
public void AssignToRequestFont(RequestFont r) { SetCacheActualFont(r, this); }
Size CalculateDrawingStringSize(char[] buffer, int length) { PixelFarm.Drawing.RequestFont fontInfo = GetFont(); return(this.Root.IFonts.MeasureString(buffer, 0, length, fontInfo)); }
public static TextureFont GetCacheFontAsTextureFont(RequestFont r) { return GetCacheActualFont(r) as TextureFont; }
internal static ActualFont GetCacheActualFont(RequestFont r) { return(r._actualFont); }
public PixelFarm.Drawing.Fonts.ActualFont Resolve(RequestFont font) { return WinGdiTextService.GetWinGdiFont(font); }
//============================================== public static void CalculateGlyphAdvancePos(char[] str, int startAt, int len, RequestFont font, int[] glyphXAdvances) { unsafe { if (len == 0) { return; } WinGdiFont winfont = SetFont(font); //ushort* glyhIndics = stackalloc ushort[len]; //fixed (char* s = &str[startAt]) //{ // NativeTextWin32.GetGlyphIndices( // win32MemDc.DC, // s, // len, // glyhIndics, // 0); //} byte[] encoding = s_en.GetBytes(str, startAt, len); NativeTextWin32.FontABC[] abcWidths = winfont.GetInteralABCArray(); for (int i = 0; i < len; ++i) { //ushort glyphIndex = *(glyhIndics + i); int enc_index = encoding[i]; if (enc_index == 0) { break;//? } glyphXAdvances[i] = abcWidths[enc_index].Sum; } } //unsafe //{ // SetFont(font); // NativeTextWin32.GCP_RESULTS gpcResult = new NativeTextWin32.GCP_RESULTS(); // int[] caretpos = new int[len]; // uint[] lpOrder = new uint[len]; // int[] lpDx = new int[len]; // fixed (int* lpdx_h = &lpDx[0]) // fixed (uint* lpOrder_h = &lpOrder[0]) // fixed (int* caretpos_h = &caretpos[0]) // fixed (char* str_h = &str[startAt]) // { // gpcResult.lpCaretPos = caretpos_h; // gpcResult.lpOrder = lpOrder_h; // gpcResult.lpDx = lpdx_h; // //gpcResult. // ////gpcResult.lpCaretPos = // NativeTextWin32.GetCharacterPlacement( // win32MemDc.DC, // str_h, // len, // len, ref gpcResult, 0); // } //} }
public Size MeasureString(char[] buff, int startAt, int len, RequestFont font) { return WinGdiTextService.MeasureString(buff, startAt, len, font); }
void InitGraphics() { //INIT ONCE if (_g != null) { return; } // _destImg = new MemBitmap(800, 600); _painter = AggPainter.Create(_destImg); _winBmp = new Bitmap(_destImg.Width, _destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _g = this.CreateGraphics(); _defaultReqFont = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 10); _painter.CurrentFont = _defaultReqFont; _textService = new Typography.Text.OpenFontTextService(); _textService.LoadFontsFromFolder("../../../TestFonts"); _textService.UpdateUnicodeRanges(); _devVxsTextPrinter = new PixelFarm.Drawing.VxsTextSpanPrinter(_painter, _textService.CreateNewServiceClient()); _devVxsTextPrinter.SetSvgBmpBuilderFunc(PaintLab.SvgBuilderHelper.ParseAndRenderSvg); _devVxsTextPrinter.ScriptLang = new ScriptLang(ScriptTagDefs.Latin.Tag); _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont; //Alternative Typeface selector.. _myAlternativeTypefaceSelector = new Typography.Text.AlternativeTypefaceSelector(); { //------------ //TODO: review this again //load from config? //------------ //arabic //1. create prefer typeface list for arabic script var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList(); preferTypefaces.AddTypefaceName("Noto Sans Arabic UI"); //2. set unicode ranges and prefered typeface list. _myAlternativeTypefaceSelector.SetPreferredTypefaces( new[] { Typography.TextBreak.Unicode13RangeInfoList.Arabic, Typography.TextBreak.Unicode13RangeInfoList.Arabic_Supplement, Typography.TextBreak.Unicode13RangeInfoList.Arabic_Extended_A }, preferTypefaces); } { //latin var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList(); preferTypefaces.AddTypefaceName("Sarabun"); _myAlternativeTypefaceSelector.SetPreferredTypefaces( new[] { Typography.TextBreak.Unicode13RangeInfoList.C0_Controls_and_Basic_Latin, Typography.TextBreak.Unicode13RangeInfoList.C1_Controls_and_Latin_1_Supplement, Typography.TextBreak.Unicode13RangeInfoList.Latin_Extended_A, Typography.TextBreak.Unicode13RangeInfoList.Latin_Extended_B, }, preferTypefaces); } _devVxsTextPrinter.AlternativeTypefaceSelector = _myAlternativeTypefaceSelector; }
public static ActualFont GetWinGdiFont(RequestFont f) { return WinGdiFontSystem.GetWinGdiFont(f); }