public SVGPackedBin[] End(bool performPacking) { int err, binsCount, rectSize; uint i, j; uint[] binInfo; SVGPackedBin[] bins; // close the current packing task if ((err = AmanithSVG.svgtPackingEnd(performPacking ? AmanithSVG.SVGT_TRUE : AmanithSVG.SVGT_FALSE)) != AmanithSVG.SVGT_NO_ERROR) { AmanithSVG.svgtErrorLog("SVGPacker.End error: ", err); return null; } // if requested, close the packing process without doing anything if (!performPacking) return null; // get number of generated bins binsCount = AmanithSVG.svgtPackingBinsCount(); if (binsCount <= 0) return null; // allocate space for bins bins = new SVGPackedBin[binsCount]; if (bins == null) return null; // allocate space to store information of a single bin binInfo = new uint[3]; if (binInfo == null) return null; #if UNITY_WP_8_1 && !UNITY_EDITOR rectSize = Marshal.SizeOf<AmanithSVG.SVGTPackedRect>(); #else rectSize = Marshal.SizeOf(typeof(AmanithSVG.SVGTPackedRect)); #endif // fill bins information j = (uint)binsCount; for (i = 0; i < j; ++i) { uint k; System.IntPtr rectsPtr; SVGPackedBin bin; // get bin information if ((err = AmanithSVG.svgtPackingBinInfo(i, binInfo)) != AmanithSVG.SVGT_NO_ERROR) { AmanithSVG.svgtErrorLog("SVGPacker.End error: ", err); return null; } // get packed rectangles rectsPtr = AmanithSVG.svgtPackingBinRects(i); if (rectsPtr == System.IntPtr.Zero) return null; // create new bin and store relative information (width, height, rectangles count) bin = new SVGPackedBin(i, binInfo[0], binInfo[1], binInfo[2]); // fill rectangles for (k = 0; k < binInfo[2]; ++k) { // rectangle generated by AmanithSVG packer #if UNITY_WP_8_1 && !UNITY_EDITOR AmanithSVG.SVGTPackedRect rect = (AmanithSVG.SVGTPackedRect)Marshal.PtrToStructure<AmanithSVG.SVGTPackedRect>(rectsPtr); #else AmanithSVG.SVGTPackedRect rect = (AmanithSVG.SVGTPackedRect)Marshal.PtrToStructure(rectsPtr, typeof(AmanithSVG.SVGTPackedRect)); #endif // build element name to be displayed in Unity editor string name = bin.GenElementName(rect); // set the rectangle bin.Rectangles[k] = new SVGPackedRectangle(rect.docHandle, rect.elemIdx, name, rect.originalX, rect.originalY, rect.x, rect.y, rect.width, rect.height, rect.zOrder/*, rect.scale*/); // next packed rectangle rectsPtr = (System.IntPtr)(rectsPtr.ToInt64() + rectSize); } bins[i] = bin; } return bins; }
public bool Draw(SVGPackedBin bin, SVGColor clearColor, SVGRenderingQuality renderingQuality) { int err; // set clear color if (!this.SetClearColor(clearColor)) return false; if (bin != null && bin.Rectangles.Length > 0) { if ((err = AmanithSVG.svgtPackingDraw(bin.Index, 0, (uint)bin.Rectangles.Length, this.Handle, (uint)renderingQuality)) != AmanithSVG.SVGT_NO_ERROR) { AmanithSVG.svgtErrorLog("Surface draw error (drawing packed bin): ", err); return false; } } return true; }