// // RiveFactory.m // RiveRuntime // // Created by Maxwell Talbot on 08/11/2023. // Copyright © 2023 Rive. All rights reserved. // #import #import #import @implementation RiveFont { rive::rcp instance; // note: we do NOT own this, so don't delete it } - (instancetype)initWithFont:(rive::rcp)font { if (self = [super init]) { instance = font; return self; } else { return nil; } } - (rive::rcp)instance { return instance; } @end @implementation RiveRenderImage { rive::rcp instance; // note: we do NOT own this, so don't delete it } - (instancetype)initWithImage:(rive::rcp)image { if (self = [super init]) { instance = image; return self; } else { return nil; } } - (rive::rcp)instance { return instance; } @end /* * RiveFactory */ @implementation RiveFactory { rive::Factory* instance; // note: we do NOT own this, so don't delete it } // Creates a new RiveFactory from a cpp RiveFactory - (instancetype)initWithFactory:(rive::Factory*)factory { if (self = [super init]) { instance = factory; return self; } else { return nil; } } - (RiveRenderImage*)decodeImage:(nonnull NSData*)data { UInt8* bytes = (UInt8*)[data bytes]; return [[RiveRenderImage alloc] initWithImage:instance->decodeImage(rive::Span(bytes, [data length]))]; } - (RiveFont*)decodeFont:(nonnull NSData*)data { UInt8* bytes = (UInt8*)[data bytes]; return [[RiveFont alloc] initWithFont:instance->decodeFont(rive::Span(bytes, [data length]))]; } @end