Clipping a bitmap render

I need to apply a custom clip/scissor rect to a DrawFittedBitmap() call (tested on NanoVG), to crop (not scale) the output to a custom rectangle.

EDIT: this works:

g->PathClipRegion(clip_rect);
g->DrawFittedBitmap(...);
// 'turn off' the clip region by setting it to the plugin dimension
g->PathClipRegion({0, 0, PLUG_WIDTH, PLUG_HEIGHT});

but ideally I’d like to restore the existing clip region, if any. is there a way to do that? or is there another way to clip a fitted bitmap?

… this seems to be the correct solution:

g->PathTransformSave();
g->PathClipRegion(clip_rect);
g->DrawFittedBitmap(...);
g->PathTransformRestore();

EDIT: actually that’s not reliable (it worked in one scenario, but in another the clipping region stayed in effect after PathTransformRestore()). this works:

g->PathClipRegion(clip_rect);
g->Draw...()
g->PathClipRegion(IRECT());