(Skia) Submit project to bindbc?

evilrat evilrat666 at gmail.com
Fri Jun 4 09:27:37 UTC 2021


On Thursday, 3 June 2021 at 11:42:05 UTC, Ola Fosheim Grøstad 
wrote:
> On Thursday, 3 June 2021 at 11:35:32 UTC, evilrat wrote:
>> Unfortunately it is still sucks because it uses STL, and there 
>> is tons of junk in it.  Maybe if I could just strip produced 
>> garbage and take only what is used (atomics, unique_ptr, 
>> strings, etc..., but not all those extra functions) it will 
>> work.
>
> So maybe it is better to write an abstraction layer in C++ that 
> can be used directly from D.
>
> Other than that, Skia is a good test case for D's C++ support.

Actually I tried this as quick hack and it writes text on top of 
C API demo.

So it is indeed just thin wrapper, and it makes possible to 
extend bindings to load text functions on top of it.

## HACK: DO NOT USE

__main.d__ (add on top)
```d
extern(C++)
{
     class SkPaint;

     alias SkScalar = float;

     enum SkTextEncoding
     {
         kUTF8,      //!< uses bytes to represent UTF-8 or ASCII
         kUTF16,     //!< uses two byte words to represent most of 
Unicode
         kUTF32,     //!< uses four byte words to represent all of 
Unicode
         kGlyphID,   //!< uses two byte words to represent glyph 
indices
     }

     final class SkCanvas
     {
         void drawSimpleText(const(void)* text, size_t byteLength, 
SkTextEncoding encoding,
                             SkScalar x, SkScalar y, ref const 
SkFont font, ref const SkPaint paint);

         alias drawSimpleTextFn = void function(SkCanvas this_,
                             const(void)* text, size_t byteLength, 
SkTextEncoding encoding,
                             SkScalar x, SkScalar y, ref const 
SkFont font, ref const SkPaint paint);
     }

     extern(C++, class)
     struct SkFont
     {
         byte[256] instanceData_; // hack, reserve enough space to 
fit all data, since I don't know actual size

         //@disable this();
         //pragma(msg, SkFont.__ctor.mangleof);

         alias ctorFn = void function(SkFont* this_);
     }
}
```


__main.d__ (insert at the end of draw function before delete 
block)
```d
void draw(sk_canvas_t* canvas) {
     // ...

     sk_paint_t* strokeText = sk_paint_new();
     sk_paint_set_stroke(strokeText, true);
     sk_paint_set_stroke_width(strokeText, 1.0f);

     import core.sys.windows.windows;
     auto lib = LoadLibrary("skia.dll");
     SkCanvas.drawSimpleTextFn drawTextFnPtr = 
cast(SkCanvas.drawSimpleTextFn) GetProcAddress(lib, 
"?drawSimpleText at SkCanvas@@QEAAXPEBX_KW4SkTextEncoding@@MMAEBVSkFont@@AEBVSkPaint@@@Z");

     SkFont fnt;
     SkFont.ctorFn skFontCtorPtr = cast(SkFont.ctorFn) 
GetProcAddress(lib, "??0SkFont@@QEAA at XZ");
     skFontCtorPtr(&fnt);

     enum text = "test dynamic text";
     drawTextFnPtr(cast(SkCanvas)canvas, text.ptr, text.length, 
SkTextEncoding.kUTF8, 150, 150, fnt, *cast(SkPaint*) strokeText);

     sk_paint_delete(strokeText);

     // deleters
}
```


More information about the Digitalmars-d mailing list