1 module skia.SKRunBuffer; 2 3 import skia.MathTypes; 4 import skia.Definitions; 5 import skia.SkiaApi; 6 7 import std.experimental.logger; 8 9 class SKRunBuffer { 10 SKRunBufferInternal internalBuffer; 11 12 this(SKRunBufferInternal buffer, int size) { 13 internalBuffer = buffer; 14 Size = size; 15 16 } 17 18 void check() { 19 20 int size = Size; 21 byte* data = cast(byte*)internalBuffer.glyphs; 22 infof("size: %d, glyphs: %(%02X %)", size, data[0 .. size*2]); 23 24 data = cast(byte*)internalBuffer.pos; 25 infof("size: %d, pos: %(%02X %)", size, data[0 .. size*2*4]); 26 27 data = cast(byte*)internalBuffer.utf8text; 28 infof("size: %d, textSize: %d, utf8text: %(%02X %)", size, TextSize, data[0 .. TextSize]); 29 } 30 31 this(SKRunBufferInternal buffer, int size, int textSize) { 32 internalBuffer = buffer; 33 Size = size; 34 TextSize = textSize; 35 } 36 37 int Size; // { get; } 38 39 int TextSize; // { get; } 40 41 ushort[] GetGlyphSpan() { 42 void* glyphs = internalBuffer.glyphs; 43 if (glyphs is null) { 44 return []; 45 } else { 46 ushort* dataPtr = cast(ushort*)glyphs; 47 ushort[] data = dataPtr[0 .. Size]; 48 return data; 49 } 50 // return new ushort[] (cast(int)(internalBuffer.glyphs), cast(int)(internalBuffer.glyphs is null ? 0 : Size)); 51 } 52 53 byte[] GetTextSpan () { 54 void* utf8text = internalBuffer.utf8text; 55 if (utf8text is null) { 56 return []; 57 } else { 58 byte* dataPtr = cast(byte*)utf8text; 59 byte[] data = dataPtr[0 .. TextSize]; 60 return data; 61 } 62 // return new byte[] (internalBuffer.utf8text, internalBuffer.utf8text is null ? 0 : TextSize); 63 } 64 65 uint[] GetClusterSpan () { 66 void* clusters = internalBuffer.clusters; 67 if (clusters is null) { 68 return []; 69 } else { 70 uint* dataPtr = cast(uint*)clusters; 71 uint[] data = dataPtr[0 .. Size]; 72 return data; 73 } 74 // return new uint[] (internalBuffer.clusters, internalBuffer.clusters is null ? 0 : Size); 75 } 76 77 void SetGlyphs(const(ushort)[] glyphs) { 78 // glyphs.CopyTo (GetGlyphSpan ()); 79 size_t len = glyphs.length; 80 ushort[] dest = GetGlyphSpan(); 81 if (len > dest.length) { 82 warning("out of range "); 83 } else { 84 dest[0 .. len] = glyphs[0 .. len]; 85 } 86 } 87 88 void SetText(const(byte)[] text) { 89 // text.CopyTo (GetTextSpan ()); 90 byte[] buffer = GetTextSpan (); 91 buffer[0 .. text.length] = text[0 .. $]; 92 } 93 94 void SetClusters(const(uint)[] clusters) { 95 // clusters.CopyTo (GetClusterSpan ()); 96 uint[] buffer = GetClusterSpan (); 97 buffer[0 .. clusters.length] = clusters[0 .. $]; 98 } 99 } 100 101 class SKHorizontalRunBuffer : SKRunBuffer { 102 this(SKRunBufferInternal buffer, int count) { 103 super(buffer, count); 104 } 105 106 this(SKRunBufferInternal buffer, int count, int textSize) { 107 super(buffer, count, textSize); 108 } 109 110 // Span!(float) GetPositionSpan () 111 // { 112 // return new float[] (internalBuffer.pos, internalBuffer.pos is null ? 0 : Size); 113 // } 114 115 void SetPositions(const(float)[] positions) { 116 // return positions.CopyTo (GetPositionSpan ()); 117 } 118 } 119 120 class SKPositionedRunBuffer : SKRunBuffer { 121 this(SKRunBufferInternal buffer, int count) { 122 super(buffer, count); 123 } 124 125 this(SKRunBufferInternal buffer, int count, int textSize) { 126 super(buffer, count, textSize); 127 } 128 129 SKPoint[] GetPositionSpan() { 130 if(internalBuffer.pos is null) 131 return null; 132 133 SKPoint* pointPtr = cast(SKPoint*)internalBuffer.pos; 134 return pointPtr[0..Size]; 135 // return SKPoint[] (internalBuffer.pos, internalBuffer.pos is null ? 0 : Size); 136 137 } 138 139 // Span!(SKPoint) GetPositionSpan () 140 // { 141 // return SKPoint[] (internalBuffer.pos, internalBuffer.pos is null ? 0 : Size); 142 // } 143 144 void SetPositions(const(SKPoint)[] positions) { 145 warning("1111"); 146 // return positions.CopyTo (GetPositionSpan ()); 147 } 148 149 } 150 151 class SKRotationScaleRunBuffer : SKRunBuffer { 152 this(SKRunBufferInternal buffer, int count) { 153 super(buffer, count); 154 } 155 156 this(SKRunBufferInternal buffer, int count, int textSize) { 157 super(buffer, count, textSize); 158 } 159 160 // Span!(SKRotationScaleMatrix) GetRotationScaleSpan () 161 // { 162 // return new SKRotationScaleMatrix[] (internalBuffer.pos, Size); 163 // } 164 165 void SetRotationScale(const(SKRotationScaleMatrix)[] positions) { 166 // return positions.CopyTo (GetRotationScaleSpan ()); 167 } 168 169 }