Skip to content

Instantly share code, notes, and snippets.

@indiscripts
Created August 2, 2022 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indiscripts/60a8945812fe371147f7f10d8f93cc16 to your computer and use it in GitHub Desktop.
Save indiscripts/60a8945812fe371147f7f10d8f93cc16 to your computer and use it in GitHub Desktop.
Testing GCO-to-BOX solution
function graphicCellObjectBox(/*PageItem*/gco, dup,t,lt,rb,xy,dx,dy)
//----------------------------------
// [DRAFT220802] Input: PageItem of a graphic cell.
{
const AP_CC = +AnchorPoint.CENTER_ANCHOR;
const AP_TL = +AnchorPoint.TOP_LEFT_ANCHOR;
const AP_BR = +AnchorPoint.BOTTOM_RIGHT_ANCHOR;
const CS_IN = +CoordinateSpaces.INNER_COORDINATES;
const CS_PAR = +CoordinateSpaces.PARENT_COORDINATES;
const CS_SPD = +CoordinateSpaces.SPREAD_COORDINATES;
const CS_PB = +CoordinateSpaces.PASTEBOARD_COORDINATES;
const BB_VIS = +BoundingBoxLimits.outerStrokeBounds;
const MC = MatrixContent;
const MC_SHR = [ MC.scaleValues, MC.shearValue, MC.rotationValue ];
dup = gco.duplicate(); // Assert: dup is a Spread item (that's all we know!)
(t=dup.pageItems).length && (t.everyItem().remove()); // Assert: dup has no inner stuff.
dup.convertShape(+ConvertShapeOptions.CONVERT_TO_RECTANGLE); // Assert: dup is a rectangular box (in its inner space!)
dup.properties = { strokeColor:'None',fillColor:'Yellow' }; // Assert: visibleBounds == geoPath
// 1. Reposition dup (in case of weird spread shift.)
// ---
xy = gco.resolve(AP_CC,CS_PB)[0]; // Center point of gco in PB space.
t = dup.resolve(AP_CC,CS_PB)[0]; // Center point of dup in PB space.
dx = xy[0]-t[0];
dy = xy[1]-t[1];
(dx||dy) && dup.transform(CS_PB,[0,0],[1,0,0,1,dx,dy]); // Reposition.
// 2. Adjust the transform state of dup so that the
// dup->Spread matrix matches the gcoParent->Spread matrix.
// ---
t = gco.transformValuesOf(CS_PAR)[0].invertMatrix() // gcoParent -> gcoInner
.catenateMatrix(gco.transformValuesOf(CS_SPD)[0]); // gcoParent -> Spread
dup.transform(CS_SPD, AP_CC, t, MC_SHR); // Assert: dup is now in good transform state!
// 3. Reframe dup w.r.t the *visible in-parent* box of gco.
// ---
lt = gco.resolve([AP_TL,BB_VIS,CS_PAR],CS_PB)[0]; // Coordinates are returned in pasteboard space
rb = gco.resolve([AP_BR,BB_VIS,CS_PAR],CS_PB)[0]; // because the *spread space is not reliable*.
t = dup.transformValuesOf(CS_PB)[0].invertMatrix(); // Pasteboard -> dupInner
lt = t.changeCoordinates(lt);
rb = t.changeCoordinates(rb);
dup.reframe(CS_IN, [lt,rb]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment