Rectangles might used when you have a background color for a text span, but one pixel off shouldn't be much of an issue.Arabetics Harfi is a Latin Serif typeface with a comprehensive support for the Arabetic scripts, including Quranic texts. (The docs mention that rectangles can be off by one pixel on the right/bottom, and arcs being calculated differently, but I don't think that would affect RichTextBox rendering too much. However processing the metafile after recording seems a bit overkill, it is a lot of work to define the necessary interop to use it from C#, so SetGraphicsMode seems to be the better choice for you if it doesn't cause other negative effects. The other two alternative workarounds to fix the font rendering involve EnumEnhMetaFile and either fixing the wrong resolution information in the metafile (so it doesn't need a world transform and can render in default graphics mode), or alternatively configuring fonts to be loaded with classic AntiAlias hinting instead of ClearType rendering. I think you could theoretically get it to work in the default graphics mode but this needs very careful setup of the DC/Metafile coordinate system to prevent any mismatch. The reason why this helps is because the metafile records a "world transform" to relate the mismatching rendering resolutions and enabling advanced graphics mode allows text rendering to respect that recorded information and figure out what the original resolution was.
![ms pgothic font typesite ms pgothic font typesite](https://cdnimg.fonts.net/CatalogImages/23/876212.png)
The number 2 is GM_ADVANCED, while the default is 1, GM_COMPATIBLE.
![ms pgothic font typesite ms pgothic font typesite](https://copyfonts.com/preview-image/2ms-pgothic_184195.jpg)
I found several workarounds, the easiest is calling SetGraphicsMode(hdc, 2) just before the SendMessage(EM_FORMATRANGE) call. This font relies on hinting to get the sharp pixel lines at low resolutions, using a metafile the way you are doing messes the resolution information up, so when drawing the metafile back to screen it gets confused about what resolution it is drawing in and (incorrectly) choses cleartype vector rendering instead of antialiased hinting.
#MS PGOTHIC FONT TYPESITE CODE#
If you change your SendMessage(EM_FORMATRANGE) code to render into a bitmap instead of a metafile everything works fine. The problems with MS PGothic font don't come from the RichTextBox, they are caused by your metafile rendering code. Or maybe this is limitation and is there any workaround to solve it? Private void button2_Click(object sender, EventArgs e)Ĭhoose any API to get correct result to paint a rich textbox like real control. Private void panel2_Paint(object sender, PaintEventArgs e) Private void button1_Click(object sender, EventArgs e) To solve this issue, we have to give up transparent back color, then issue is fixed: More detail please reference TestRichTextBoxNETCoreWithAPIįont is not good if set rich textbox transparent: UnsafeNativeMethods.SendMessage(new HandleRef(this.myRichTextBox1, ), UnsafeNativeMethods.EM_FORMATRANGE, IntPtr.Zero, IntPtr.Zero) Į.Graphics.DrawImage(buffer, render.Bounds, 0f, 0f, (float), (float), GraphicsUnit.Pixel) UnsafeNativeMethods.SendMessage(new HandleRef(this.myRichTextBox1, ), UnsafeNativeMethods.EM_FORMATRANGE, new IntPtr(1), ref fmt) Using (Graphics bufferGraphics = Graphics.FromImage(buffer)) MetafileFrameUnit.Pixel, EmfType.EmfPlusDual))
![ms pgothic font typesite ms pgothic font typesite](https://www.free-fonts.com/images/myfonts/ms_kitty_nb_60086410.gif)
Using (Metafile buffer = new Metafile((), new RectangleF(0f, 0f, (float), (float)), Private void panel1_Paint(object sender, PaintEventArgs e)