diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-05-07 08:12:56 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-05-07 08:12:56 +0200 |
| commit | 6b02331dfe7c6d8290c136ce20b4a7c655b47aae (patch) | |
| tree | da414ee19018edaf1d37b8fd7a6e4fe1f86edecd /vkvg | |
| parent | f3344a78e511213d235e4c91bf507264fd41ac0d (diff) | |
first tests with vkvg as backendvkvg
Diffstat (limited to 'vkvg')
| -rw-r--r-- | vkvg/Context.cs | 243 | ||||
| -rw-r--r-- | vkvg/Device.cs | 64 | ||||
| -rw-r--r-- | vkvg/Enums.cs | 61 | ||||
| -rw-r--r-- | vkvg/FontExtents.cs | 104 | ||||
| -rw-r--r-- | vkvg/NativeMethods.cs | 137 | ||||
| -rw-r--r-- | vkvg/PointD.cs | 58 | ||||
| -rw-r--r-- | vkvg/Surface.cs | 90 | ||||
| -rw-r--r-- | vkvg/TextExtents.cs | 98 |
8 files changed, 855 insertions, 0 deletions
diff --git a/vkvg/Context.cs b/vkvg/Context.cs new file mode 100644 index 00000000..029bd42f --- /dev/null +++ b/vkvg/Context.cs @@ -0,0 +1,243 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// Copyright (c) 2018 jp +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using Crow; +using System.Text; + +namespace vkvg +{ + public class Context: IDisposable + { + + IntPtr handle = IntPtr.Zero; + + public Context (Surface surf) + { + handle = NativeMethods.vkvg_create (surf.Handle); + } + ~Context () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + + public double LineWidth { + set { NativeMethods.vkvg_set_line_width (handle, (float)value); } + } + public uint FontSize { + set { NativeMethods.vkvg_set_font_size (handle, value); } + } + public string FontFace { + set { NativeMethods.vkvg_select_font_face (handle, value); } + } + public Operator Operator { + set { NativeMethods.vkvg_set_operator (handle, value); } + get { return NativeMethods.vkvg_get_operator (handle); } + } + public FontExtents FontExtents { + get { + FontExtents f_extents; + NativeMethods.vkvg_font_extents (handle, out f_extents); + return f_extents; + } + } + public TextExtents TextExtents(string s) + { + TextExtents extents; + NativeMethods.vkvg_text_extents (handle, TerminateUtf8(s), out extents); + return extents; + } + public void ShowText (string txt) { + NativeMethods.vkvg_show_text (handle, txt); + } + public void Save () { + NativeMethods.vkvg_save (handle); + } + public void Restore () { + NativeMethods.vkvg_restore (handle); + } + public void Flush () { + NativeMethods.vkvg_flush (handle); + } + + public void Paint () { + NativeMethods.vkvg_paint (handle); + } + public void Arc (float xc, float yc, float radius, float a1, float a2) { + NativeMethods.vkvg_arc (handle, xc, yc, radius, a1, a2); + } + public void Arc (double xc, double yc, double radius, double a1, double a2) { + NativeMethods.vkvg_arc (handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2); + } + public void ArcNegative (float xc, float yc, float radius, float a1, float a2) { + NativeMethods.vkvg_arc_negative (handle, xc, yc, radius, a1, a2); + } + public void Rectangle (float x, float y, float width, float height) { + NativeMethods.vkvg_rectangle (handle, x, y, width, height); + } + public void Scale (float sx, float sy) { + NativeMethods.vkvg_scale (handle, sx, sy); + } + public void Translate (float dx, float dy) { + NativeMethods.vkvg_translate (handle, dx, dy); + } + public void Rotate (float alpha) { + NativeMethods.vkvg_rotate (handle, alpha); + } + public void ArcNegative (double xc, double yc, double radius, double a1, double a2) { + NativeMethods.vkvg_arc_negative (handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2); + } + public void Rectangle (double x, double y, double width, double height) { + NativeMethods.vkvg_rectangle (handle, (float)x, (float)y, (float)width, (float)height); + } + public void Scale (double sx, double sy) { + NativeMethods.vkvg_scale (handle, (float)sx, (float)sy); + } + public void Translate (double dx, double dy) { + NativeMethods.vkvg_translate (handle, (float)dx, (float)dy); + } + public void Rotate (double alpha) { + NativeMethods.vkvg_rotate (handle, (float)alpha); + } + + public void Fill () { + NativeMethods.vkvg_fill (handle); + } + public void FillPreserve () { + NativeMethods.vkvg_fill_preserve (handle); + } + public void Stroke () { + NativeMethods.vkvg_stroke (handle); + } + public void StrokePreserve () { + NativeMethods.vkvg_stroke_preserve (handle); + } + public void Clip () { + NativeMethods.vkvg_clip (handle); + } + public void ClipPreserve () { + NativeMethods.vkvg_clip_preserve (handle); + } + public void ResetClip () { + NativeMethods.vkvg_reset_clip (handle); + } + public void ClosePath () { + NativeMethods.vkvg_close_path (handle); + } + +// public void Rectangle (float x, float y, float width, float height){ +// NativeMethods.vkvg_rectangle (); +// } + public void MoveTo (PointD p){ + NativeMethods.vkvg_move_to (handle, (float)p.X, (float)p.Y); + } + public void MoveTo (float x, float y){ + NativeMethods.vkvg_move_to (handle, x, y); + } + public void RelMoveTo (float x, float y){ + NativeMethods.vkvg_rel_move_to (handle, x, y); + } + public void LineTo (float x, float y){ + NativeMethods.vkvg_line_to (handle, x, y); + } + public void LineTo (Point p){ + NativeMethods.vkvg_line_to (handle, p.X, p.Y); + } + public void LineTo (PointD p){ + NativeMethods.vkvg_line_to (handle, (float)p.X, (float)p.Y); + } + public void RelLineTo (float x, float y){ + NativeMethods.vkvg_rel_line_to (handle, x, y); + } + public void CurveTo (float x1, float y1, float x2, float y2, float x3, float y3){ + NativeMethods.vkvg_curve_to (handle, x1, y1, x2, y2, x3, y3); + } + public void RelCurveTo (float x1, float y1, float x2, float y2, float x3, float y3){ + NativeMethods.vkvg_rel_curve_to (handle, x1, y1, x2, y2, x3, y3); + } + + public void MoveTo (double x, double y){ + NativeMethods.vkvg_move_to (handle, (float)x, (float)y); + } + public void RelMoveTo (double x, double y){ + NativeMethods.vkvg_rel_move_to (handle, (float)x, (float)y); + } + public void LineTo (double x, double y){ + NativeMethods.vkvg_line_to (handle, (float)x, (float)y); + } + public void RelLineTo (double x, double y){ + NativeMethods.vkvg_rel_line_to (handle, (float)x, (float)y); + } + public void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3){ + NativeMethods.vkvg_curve_to (handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); + } + public void RelCurveTo (double x1, double y1, double x2, double y2, double x3, double y3){ + NativeMethods.vkvg_rel_curve_to (handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); + } + + + public void SetSource (float r, float g, float b, float a = 1f) { + NativeMethods.vkvg_set_source_rgba (handle, r, g, b, a); + } + public void SetSource (double r, double g, double b, double a = 1.0) { + NativeMethods.vkvg_set_source_rgba (handle, (float)r, (float)g, (float)b, (float)a); + } + public void SetSource (Surface surf, float x = 0f, float y = 0f) { + NativeMethods.vkvg_set_source_surface (handle, surf.Handle, x, y); + } + public void SetSourceSurface (Surface surf, float x = 0f, float y = 0f) { + NativeMethods.vkvg_set_source_surface (handle, surf.Handle, x, y); + } + + private static byte[] TerminateUtf8(string s) + { + // compute the byte count including the trailing \0 + var byteCount = Encoding.UTF8.GetMaxByteCount(s.Length + 1); + var bytes = new byte[byteCount]; + Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0); + return bytes; + } + + #region IDisposable implementation + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing || handle == IntPtr.Zero) + return; + + NativeMethods.vkvg_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkvg/Device.cs b/vkvg/Device.cs new file mode 100644 index 00000000..09eca7ae --- /dev/null +++ b/vkvg/Device.cs @@ -0,0 +1,64 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// Copyright (c) 2018 jp +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; + +namespace vkvg +{ + public class Device: IDisposable + { + + IntPtr handle = IntPtr.Zero; + + public Device (vkglfw.VkEngine engine) + { + handle = NativeMethods.vkvg_device_create (engine.Phy, engine.Device, engine.QueueFamIdx, 0); + } + ~Device () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + + #region IDisposable implementation + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing || handle == IntPtr.Zero) + return; + + NativeMethods.vkvg_device_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkvg/Enums.cs b/vkvg/Enums.cs new file mode 100644 index 00000000..499ad135 --- /dev/null +++ b/vkvg/Enums.cs @@ -0,0 +1,61 @@ +// +// Enums.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// Copyright (c) 2013-2017 Jean-Philippe Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; + +namespace vkvg +{ + public enum Operator + { + Clear, + Source, + Over, + In, + Out, + Atop, + + Dest, + DestOver, + DestIn, + DestOut, + DestAtop, + + Xor, + Add, + Saturate, + } + public enum FontSlant + { + Normal, + Italic, + Oblique + } + public enum FontWeight + { + Normal, + Bold, + } +} + diff --git a/vkvg/FontExtents.cs b/vkvg/FontExtents.cs new file mode 100644 index 00000000..c7f793df --- /dev/null +++ b/vkvg/FontExtents.cs @@ -0,0 +1,104 @@ +// +// Mono.Cairo.FontExtents.cs +// +// Authors: Duncan Mak (duncan@ximian.com) +// Hisham Mardam Bey (hisham.mardambey@gmail.com) +// +// (C) Ximian, Inc. 2003 +// +// This is a simplistic binding of the Cairo API to C#. All functions +// in cairo.h are transcribed into their C# equivelants +// +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Runtime.InteropServices; + +namespace vkvg +{ + [StructLayout (LayoutKind.Sequential)] + public struct FontExtents + { + float ascent; + float descent; + float height; + float maxXAdvance; + float maxYAdvance; + + public float Ascent { + get { return ascent; } + set { ascent = value; } + } + + public float Descent { + get { return descent; } + set { descent = value; } + } + + public float Height { + get { return height; } + set { height = value; } + } + + public float MaxXAdvance { + get { return maxXAdvance; } + set { maxXAdvance = value; } + } + + public float MaxYAdvance { + get { return maxYAdvance; } + set { maxYAdvance = value; } + } + + public FontExtents (float ascent, float descent, float height, float maxXAdvance, float maxYAdvance) + { + this.ascent = ascent; + this.descent = descent; + this.height = height; + this.maxXAdvance = maxXAdvance; + this.maxYAdvance = maxYAdvance; + } + + public override bool Equals (object obj) + { + if (obj is FontExtents) + return this == (FontExtents) obj; + return false; + } + + public override int GetHashCode () + { + return (int) Ascent ^ (int) Descent ^ (int) Height ^ (int) MaxXAdvance ^ (int) MaxYAdvance; + } + + public static bool operator == (FontExtents extents, FontExtents other) + { + return extents.Ascent == other.Ascent && extents.Descent == other.Descent && extents.Height == other.Height && extents.MaxXAdvance == other.MaxXAdvance && extents.MaxYAdvance == other.MaxYAdvance; + } + + public static bool operator != (FontExtents extents, FontExtents other) + { + return !(extents == other); + } + } +} diff --git a/vkvg/NativeMethods.cs b/vkvg/NativeMethods.cs new file mode 100644 index 00000000..1cd3854e --- /dev/null +++ b/vkvg/NativeMethods.cs @@ -0,0 +1,137 @@ +// +// NativeMethods.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// Copyright (c) 2018 jp +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Runtime.InteropServices; + +namespace vkvg +{ + internal static class NativeMethods + { + const string libvkvg = "vkvg"; + + #region Device + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_device_create (IntPtr phy, IntPtr dev, uint qFamIdx, uint qIndex); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_device_destroy (IntPtr device); + #endregion + + #region Context + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_create (IntPtr surface); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_destroy (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_flush (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_close_path (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_line_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rel_line_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_move_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rel_move_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_curve_to (IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rel_curve_to (IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rectangle (IntPtr ctx, float x, float y, float width, float height); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_arc (IntPtr ctx, float xc, float yc, float radius, float a1, float a2); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_arc_negative (IntPtr ctx, float xc, float yc, float radius, float a1, float a2); + + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_scale (IntPtr ctx, float sx, float sy); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_translate (IntPtr ctx, float dx, float dy); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rotate (IntPtr ctx, float alpha); + + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_stroke (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_stroke_preserve (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_clip (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_clip_preserve (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_reset_clip (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_fill (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_fill_preserve (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_paint (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_source_rgba (IntPtr ctx, float r, float g, float b, float a); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_line_width (IntPtr ctx, float width); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_operator (IntPtr ctx, Operator op); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern Operator vkvg_get_operator (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_source_surface(IntPtr ctx, IntPtr surf, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_font_extents (IntPtr ctx, out FontExtents extents); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_text_extents (IntPtr ctx, byte[] utf8, out TextExtents extents); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_select_font_face (IntPtr ctx, string name); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_font_size (IntPtr ctx, uint size); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_show_text (IntPtr ctx, string text); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_save (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_restore (IntPtr ctx); + #endregion + + #region Surface + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_surface_create (IntPtr device, uint width, uint height); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_surface_create_from_image (IntPtr dev, string filePath); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_surface_create_from_bitmap (IntPtr dev, ref byte[] data, uint width, uint height); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_surface_destroy (IntPtr surf); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_surface_get_vk_image (IntPtr surf); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern int vkvg_surface_get_width (IntPtr surf); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern int vkvg_surface_get_height (IntPtr surf); + #endregion + } +} + diff --git a/vkvg/PointD.cs b/vkvg/PointD.cs new file mode 100644 index 00000000..a36f8178 --- /dev/null +++ b/vkvg/PointD.cs @@ -0,0 +1,58 @@ +// +// Mono.Context.cs +// +// Author: +// Duncan Mak (duncan@ximian.com) +// Miguel de Icaza (miguel@novell.com) +// Hisham Mardam Bey (hisham.mardambey@gmail.com) +// Alp Toker (alp@atoker.com) +// +// (C) Ximian Inc, 2003. +// (C) Novell Inc, 2003. +// +// This is an OO wrapper API for the Cairo API. +// +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace vkvg { + + public struct PointD + { + public PointD (double x, double y) + { + this.x = x; + this.y = y; + } + + double x, y; + public double X { + get { return x; } + set { x = value; } + } + + public double Y { + get { return y; } + set { y = value; } + } + } +} diff --git a/vkvg/Surface.cs b/vkvg/Surface.cs new file mode 100644 index 00000000..f8595c2b --- /dev/null +++ b/vkvg/Surface.cs @@ -0,0 +1,90 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// Copyright (c) 2018 jp +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; + +namespace vkvg +{ + public class Surface: IDisposable + { + IntPtr handle = IntPtr.Zero; + Device vkvgDev; + + public Surface (Device device, int width, int heigth) + { + vkvgDev = device; + handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)heigth); + } + public Surface (Device device, ref byte[] data, int width, int heigth) + { + vkvgDev = device; + handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)heigth); + } + public Surface (Device device, string imgPath) { + vkvgDev = device; + handle = NativeMethods.vkvg_surface_create_from_image (device.Handle, imgPath); + } + + Surface (IntPtr devHandle, int width, int heigth) + { + handle = NativeMethods.vkvg_surface_create (devHandle, (uint)width, (uint)heigth); + } + ~Surface () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + public IntPtr VkImage { get { return NativeMethods.vkvg_surface_get_vk_image (handle); }} + public int Width { get { return NativeMethods.vkvg_surface_get_width (handle); }} + public int Height { get { return NativeMethods.vkvg_surface_get_height (handle); }} + +// public Surface CreateSimilar (uint width, uint height) { +// return new Surface (handle, width, height); +// } +// public Surface CreateSimilar (int width, int height) { +// return new Surface (handle, (uint)width, (uint)height); +// } + + public void Flush () {} + #region IDisposable implementation + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing || handle == IntPtr.Zero) + return; + + NativeMethods.vkvg_surface_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkvg/TextExtents.cs b/vkvg/TextExtents.cs new file mode 100644 index 00000000..2305d9a1 --- /dev/null +++ b/vkvg/TextExtents.cs @@ -0,0 +1,98 @@ +// +// Mono.Cairo.TextExtents.cs +// +// Authors: +// Duncan Mak (duncan@ximian.com) +// Hisham Mardam Bey (hisham.mardambey@gmail.com) +// +// (C) Ximian, Inc. 2003 +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Runtime.InteropServices; + +namespace vkvg +{ + [StructLayout (LayoutKind.Sequential)] + public struct TextExtents + { + float xbearing; + float ybearing; + float width; + float height; + float xadvance; + float yadvance; + + public float XBearing { + get { return xbearing; } + set { xbearing = value; } + } + + public float YBearing { + get { return ybearing; } + set { ybearing = value; } + } + + public float Width { + get { return width; } + set { width = value; } + } + + public float Height { + get { return height; } + set { height = value; } + } + + public float XAdvance { + get { return xadvance; } + set { xadvance = value; } + } + + public float YAdvance { + get { return yadvance; } + set { yadvance = value; } + } + + public override bool Equals (object obj) + { + if (obj is TextExtents) + return this == (TextExtents)obj; + return false; + } + + public override int GetHashCode () + { + return (int)XBearing ^ (int)YBearing ^ (int)Width ^ (int)Height ^ (int)XAdvance ^ (int)YAdvance; + } + + public static bool operator == (TextExtents extents, TextExtents other) + { + return extents.XBearing == other.XBearing && extents.YBearing == other.YBearing && extents.Width == other.Width && extents.Height == other.Height && extents.XAdvance == other.XAdvance && extents.YAdvance == other.YAdvance; + } + + public static bool operator != (TextExtents extents, TextExtents other) + { + return !(extents == other); + } + } +} |