### Run Bitmap Example Source: https://github.com/humbleui/skija/blob/master/examples/bitmap/README.md Navigates to the bitmap example directory and runs the script. This demonstrates rendering to an in-memory bitmap and saving it. ```shell cd examples/bitmap ./script/run.sh ``` -------------------------------- ### Install Skija Master Build Source: https://github.com/humbleui/skija/blob/master/examples/bitmap/README.md Installs the latest master build of Skija locally. Ensure Skija is installed before running the examples. ```shell ./script/install.sh ``` -------------------------------- ### Run Skija Clojure Examples Source: https://github.com/humbleui/skija/blob/master/examples/clojure/README.md Execute the provided script to run the Skija Clojure examples. Ensure all prerequisites are met before running. ```sh ./script/run.py ``` -------------------------------- ### Build Skija from Source Source: https://github.com/humbleui/skija/blob/master/README.md Clone the Skija repository and run the build script. Ensure you have Git, CMake, Ninja, JDK 9+, $JAVA_HOME, and Python 3 installed. For codesigning on macOS, set the APPLE_CODESIGN_IDENTITY environment variable. ```sh git clone https://github.com/HumbleUI/Skija.git cd skija ./script/build.py ``` ```sh security find-identity export APPLE_CODESIGN_IDENTITY="<...>" ./script/build.py ``` -------------------------------- ### Color4f Class Definition Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Example definition of a Color4f class with public final fields for RGBA values. Includes constructors for convenience. ```java @AllArgsConstructor @Data public class Color4f { public final float _r; public final float _g; public final float _b; public final float _a; public Color4f(float r, float g, float b) { this(r, g, b, 1f) } public Color4f(float[] rgba) { this(rgba[0], rgba[1], rgba[2], rgba[3]) } } ``` -------------------------------- ### C++ LineMetrics Class Source: https://github.com/humbleui/skija/blob/master/docs/Conventions.md Example of a C++ class definition for LineMetrics, including fields and enum flags. ```cpp class LineMetrics { public: size_t fStartIndex = 0; size_t fEndIndex = 0; size_t fEndExcludingWhitespaces = 0; size_t fEndIncludingNewline = 0; bool fHardBreak = false; int fFlags = 0; enum Flags { kIsBold_Flag = 1, kIsItalic_Flag = 2, }; } ``` -------------------------------- ### Automatic Resource Management (Default) Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Skija objects extending RefCnt or Managed are automatically managed. Native resources are freed when Java objects are garbage collected. This example shows a safe way to draw a circle. ```java void drawCircle(Canvas c) { Paint p = new Paint() c.drawCircle(0, 0, 10, p) } // Totally OK, `p` will be freed at the next GC ``` -------------------------------- ### Encode and Save Image Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Convert the drawn content to a PNG image, get its byte data, and write it to a file named 'output.png'. Handles potential IOExceptions. ```java Image image = surface.makeImageSnapshot() Data pngData = image.encodeToData(EncodedImageFormat.PNG) ByteBuffer pngBytes = pngData.toByteBuffer() try { java.nio.file.Path path = java.nio.file.Path.of("output.png") ByteChannel channel = Files.newByteChannel( path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE) channel.write(pngBytes) channel.close() } catch (IOException e) { System.out.println(e) } ``` -------------------------------- ### Build and Run Skija Demo Locally Source: https://github.com/humbleui/skija/blob/master/examples/jwm/README.md Build Skija locally and then run the demo using the locally built version. This requires building Skija first. ```python python3 ../../script/build.py python3 script/run.py ``` -------------------------------- ### Initialize Skija OpenGL with LWJGL Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Set up an OpenGL window and Skija context using LWJGL for rendering. Ensure to initialize OpenGL capabilities and create the Skia OpenGL context once per application launch. The render target and surface should be recreated on window resize. ```java var width = 640; var height = 480; // Create window glfInit(); glfWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfWindowHint(GLFW_RESIZABLE, GLFW_TRUE); long windowHandle = glfCreateWindow(width, height, "Skija LWJGL Demo", NULL, NULL); glfMakeContextCurrent(windowHandle); glfSwapInterval(1); // Enable v-sync glfShowWindow(windowHandle); // Initialize OpenGL // Do once per app launch GL.createCapabilities(); // Create Skia OpenGL context // Do once per app launch DirectContext context = DirectContext.makeGL(); // Create render target, surface and retrieve canvas from it // .close() and recreate on window resize int fbId = GL11.glGetInteger(0x8CA6); // GL_FRAMEBUFFER_BINDING BackendRenderTarget renderTarget = BackendRenderTarget.makeGL( width, height, /*samples*/ 0, /*stencil*/ 8, fbId, FramebufferFormat.GR_GL_RGBA8); // .close() and recreate on window resize Surface surface = Surface.makeFromBackendRenderTarget( context, renderTarget, SurfaceOrigin.BOTTOM_LEFT, ColorType.RGBA_8888, ColorSpace.getSRGB()); // do not .close() — Surface manages its lifetime here Canvas canvas = surface.getCanvas(); // Render loop while (!glfwWindowShouldClose(windowHandle)) { // DRAW HERE!!! context.flush(); glfwSwapBuffers(windowHandle); // wait for v-sync glfwPollEvents(); } ``` -------------------------------- ### Run Skija Demo with Maven Version Source: https://github.com/humbleui/skija/blob/master/examples/jwm/README.md Execute the Skija demo using specific versions from Maven. Ensure you have the necessary script. ```python python3 script/run.py --skija-version 0.100.0 --jwm-version 0.4.1 ``` -------------------------------- ### Run Skija LWJGL Demo with Maven Version Source: https://github.com/humbleui/skija/blob/master/examples/lwjgl/README.md Execute the Skija LWJGL demo using a specific version fetched from Maven. Ensure you have the script and the specified Skija version available. ```bash python3 script/run.py --skija-version 0.89.1 ``` -------------------------------- ### Manual Resource Management (Optional) Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Optionally, you can use try-with-resources for immediate freeing of short-lived Skija objects. This is not mandatory but can help free memory sooner. ```java void drawCircle(Canvas c) { try (Paint p = new Paint()) { c.drawCircle(0, 0, 10, p) } // `p` will be freed right here, cleaning up C++ resources. Can’t be used after! ``` -------------------------------- ### Generate IntelliJ IDEA Project Files Source: https://github.com/humbleui/skija/blob/master/README.md Use this script to generate the necessary project files for opening the Skija project in IntelliJ IDEA. ```sh ./script/idea.py ``` -------------------------------- ### Chained Paint Setters Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Demonstrates chaining multiple setter methods on a Paint object for concise configuration. ```java var paint = new Paint().setColor(0xFF1D7AA2).setMode(PaintMode.STROKE).setStrokeWidth(1f) ``` -------------------------------- ### Create Vulkan DirectContext in Skija Source: https://github.com/humbleui/skija/blob/master/examples/vulkan/README.md Use this method to create a DirectContext for Skija with Vulkan. Ensure you have a Vulkan-capable GPU and the necessary Vulkan instance, device, and queue handles. ```java DirectContext.makeVulkan( vkInstance, vkPhysicalDevice, vkDevice, vkQueue, queueIndex, vkGetInstanceProcAddr, vkGetDeviceProcAddr ); ``` -------------------------------- ### Import Skija Classes Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Import the necessary Skija classes and Java IO classes in your main application file. ```java import io.github.humbleui.skija.* import java.io.IOException ``` -------------------------------- ### Accessing Color4f Properties Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Demonstrates the recommended way to access Color4f properties using getter methods, rather than directly accessing fields prefixed with '_'. ```java var color = new Color4f(1, 1, 1) color._r; // bad: encapsulation breach. Don’t do this color.getR() // good: proper public API use ``` -------------------------------- ### Create In-Memory Canvas Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Create a raster-backed in-memory Surface and obtain its Canvas object for drawing operations. ```java Surface surface = Surface.makeRasterN32Premul(100, 100) Canvas canvas = surface.getCanvas() ``` -------------------------------- ### Java LineMetrics Class Conversion Source: https://github.com/humbleui/skija/blob/master/docs/Conventions.md Demonstrates the conversion of the C++ LineMetrics class to a Java equivalent, adhering to Skija's conventions such as public final fields prefixed with '_', getters/setters, and static final constants for flags. ```java @Data public class LineMetrics { public final long _startIndex; public final long _endIndex; public final long _endExcludingWhitespaces; public final long _endIncludingNewline; public final boolean _hardBreak; @Getter(AccessLevel.NONE) public final int _flags; public static final int _FLAG_IS_BOLD = 0b0001; public static final int _FLAG_IS_ITALIC = 0b0010; public boolean isBold() { return (_flags | _FLAG_IS_BOLD) != 0; } public boolean isItalic() { return (_flags | _FLAG_IS_ITALIC) != 0; } } ``` -------------------------------- ### Define Paint Color Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Create a Paint object and set its fill color using a 32-bit ARGB integer. Fully opaque is `0xFF______`, fully transparent is `0x00______`. ```java Paint paint = new Paint() paint.setColor(0xFFFF0000) ``` -------------------------------- ### Create Typeface from Font File Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Create a Typeface object from a font file. This operation can be expensive, so it's recommended to cache Typeface objects. ```java Typeface face = FontMgr.getDefault().makeFromFile("Inter.ttf"); ``` -------------------------------- ### Add Skija Dependency Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Include one of these dependencies in your build file to add Skija to your project. Replace `${version}` with the latest version number. ```gradle io.github.humbleui:skija-windows-x64:${version} ``` ```gradle io.github.humbleui:skija-linux-x64:${version} ``` ```gradle io.github.humbleui:skija-linux-arm64:${version} ``` ```gradle io.github.humbleui:skija-macos-x64:${version} ``` ```gradle io.github.humbleui:skija-macos-arm64:${version} ``` ```gradle io.github.humbleui:skija-android-x64:${version} ``` ```gradle io.github.humbleui:skija-android-arm64:${version} ``` -------------------------------- ### Match Typeface by Family and Style Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Find a Typeface that matches the specified family name and font style. This is useful for selecting system fonts. ```java Typeface face = FontMgr.getDefault().matchFamilyStyle("Menlo", FontStyle.NORMAL); ``` -------------------------------- ### Draw a Circle Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Draw a circle on the canvas using the specified coordinates, radius, and paint settings. ```java canvas.drawCircle(50, 50, 30, paint) ``` -------------------------------- ### Add Skija Dependency with Gradle Source: https://github.com/humbleui/skija/blob/master/README.md Use this Gradle dependency to include Skija in your project. Replace `${artifact}` and `${version}` with the appropriate values for your target platform. ```gradle dependencies { implementation("io.github.humbleui:${artifact}:${version}") } ``` -------------------------------- ### Create Font with Specific Size Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Create a Font object with a given Typeface and size. Font objects define text rendering properties like size. ```java Font font = new Font(face, 13); ``` -------------------------------- ### Add Skija Dependency with Maven Source: https://github.com/humbleui/skija/blob/master/README.md Use this Maven dependency to include Skija in your project. Replace `${artifact}` and `${version}` with the appropriate values for your target platform. ```xml io.github.humbleui ${artifact} ${version} ``` -------------------------------- ### Draw Text on Canvas Source: https://github.com/humbleui/skija/blob/master/docs/Getting Started.md Draw a string on the canvas using a specified Font and Paint object. It's recommended to cache Typeface and Font objects for performance in real applications. ```java try (Typeface face = FontMgr.getDefault().matchFamilyStyle("Menlo", FontStyle.NORMAL); Font font = new Font(face, 13); Paint fill = new Paint().setColor(0xFF000000);) { canvas.drawString("Hello, world", 0, 0, font, fill); } ``` -------------------------------- ### Java Canvas Implementation for drawRRect Source: https://github.com/humbleui/skija/blob/master/docs/Conventions.md Java implementation of the drawRRect method, which calls the native JNI function. It handles object conversion and calls the native method with appropriate parameters. ```java public class Canvas extends Managed { public enum PointMode { POINTS, LINES, POLYGON } public Canvas drawRRect(RRect rr, Paint paint) { Native.onNativeCall(); _nDrawRRect(ptr, rr.left, rr.top, rr.right, rr.bottom, rr.radii, Native.ptr(paint)); return this; } public static native void _nDrawRRect(long ptr, float left, float top, float right, float bottom, float[] radii, long paintPtr); ``` -------------------------------- ### C++ SkCanvas Definition Source: https://github.com/humbleui/skija/blob/master/docs/Conventions.md Defines the C++ interface for SkCanvas, including an enum for PointMode and the drawRRect method signature. ```cpp class SK_API SkCanvas { public: enum PointMode { kPoints_PointMode, kLines_PointMode, kPolygon_PointMode, }; void drawRRect(const SkRRect& rrect, const SkPaint& paint); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.