From: Jean-Philippe Bruyère Date: Mon, 1 Feb 2021 13:56:00 +0000 (+0100) Subject: dont fix utf8 ref char, it's fixed by marshaler X-Git-Tag: v0.9.5-beta~88 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=3d09f3bd6062d9a0f36693541192bc014376fa76;p=jp%2Fcrow.git dont fix utf8 ref char, it's fixed by marshaler --- diff --git a/Crow/src/Mono.Cairo/Context.cs b/Crow/src/Mono.Cairo/Context.cs index 45600929..9253424e 100644 --- a/Crow/src/Mono.Cairo/Context.cs +++ b/Crow/src/Mono.Cairo/Context.cs @@ -884,17 +884,10 @@ namespace Crow.Cairo { Span bytes = size > 512 ? new byte[size] : stackalloc byte[size]; int encodedBytes = Crow.Text.Encoding.ToUtf8 (s, bytes, tabSize); bytes[encodedBytes] = 0; - - NativeMethods.cairo_show_text (handle, ref bytes.Slice (0, encodedBytes + 1).GetPinnableReference ()); + ShowText (bytes.Slice (0, encodedBytes + 1)); } public TextExtents TextExtents (ReadOnlySpan s, int tabSize) { - TextExtents extents; - int size = s.Length * 4 + 1; - Span bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - int encodedBytes = Crow.Text.Encoding.ToUtf8 (s, bytes, tabSize); - bytes[encodedBytes] = 0; - - NativeMethods.cairo_text_extents (handle, ref bytes.Slice (0, encodedBytes + 1).GetPinnableReference (), out extents); + TextExtents (s, tabSize, out TextExtents extents); return extents; } public void TextExtents (ReadOnlySpan s, int tabSize, out TextExtents extents) { @@ -902,22 +895,14 @@ namespace Crow.Cairo { Span bytes = size > 512 ? new byte[size] : stackalloc byte[size]; int encodedBytes = Crow.Text.Encoding.ToUtf8 (s, bytes, tabSize); bytes[encodedBytes] = 0; - - NativeMethods.cairo_text_extents (handle, ref bytes.Slice (0, encodedBytes + 1).GetPinnableReference (), out extents); + TextExtents (bytes.Slice (0, encodedBytes + 1), out extents); } - public void TextExtents (ReadOnlySpan s, out TextExtents extents) { - int size = s.Length * 4 + 1; - Span bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - int encodedBytes = Crow.Text.Encoding.ToUtf8 (s, bytes); - bytes[encodedBytes] = 0; - - NativeMethods.cairo_text_extents (handle, ref bytes.Slice (0, encodedBytes + 1).GetPinnableReference (), out extents); + public void ShowText (Span bytes) { + NativeMethods.cairo_show_text (handle, ref bytes.GetPinnableReference()); } - public void ShowText (Span bytes) => - NativeMethods.cairo_show_text (handle, ref bytes.GetPinnableReference ()); - public void TextExtents (Span bytes, out TextExtents extents) => + public void TextExtents (Span bytes, out TextExtents extents) { NativeMethods.cairo_text_extents (handle, ref bytes.GetPinnableReference (), out extents); - + } public TextExtents GlyphExtents (Glyph[] glyphs) {