From 3d09f3bd6062d9a0f36693541192bc014376fa76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 1 Feb 2021 14:56:00 +0100 Subject: [PATCH] dont fix utf8 ref char, it's fixed by marshaler --- Crow/src/Mono.Cairo/Context.cs | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) 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) { -- 2.47.3