Skip to content

Commit

Permalink
[ve] Use group flipV flipH (fix 9 compex floor drawing door); Fix 72918
Browse files Browse the repository at this point in the history
  • Loading branch information
fedek1324 committed Feb 17, 2025
1 parent 2457820 commit 87d3961
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 33 deletions.
5 changes: 5 additions & 0 deletions common/Drawings/Format/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@

const TEXT_RECT_ERROR = 0.01;

/**
*
* @constructor
*/
function CShape() {
AscFormat.CGraphicObjectBase.call(this);
this.nvSpPr = null;
Expand Down Expand Up @@ -5328,6 +5332,7 @@
};

/**
* note: sometimes call to recalculate bounds
* @memberOf CShape
*/
CShape.prototype.draw = function (graphics, transform, transformText, pageIndex, opt) {
Expand Down
12 changes: 12 additions & 0 deletions visio/model/VisioDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,18 @@
* @param {number} pageIndex
*/
CVisioDocument.prototype.draw = function(Zoom, pGraphics, pageIndex) {
/**
*
* @param graphics
* @param {(CShape | CGroupShape)} shapeOrGroup
* @param baseMatrix
* @param baseTextMatrix
* @param isRecalculateTextY
* @param isFlipImages
* @param isAdditionalRecalculate
* @param logic_h_mm
* @param {CGroupShape?} currentGroupHandling
*/
function drawShapeOrGroupRecursively(graphics, shapeOrGroup, baseMatrix, baseTextMatrix,
isRecalculateTextY, isFlipImages, isAdditionalRecalculate, logic_h_mm, currentGroupHandling) {
// see sdkjs/common/Shapes/Serialize.js this.ReadGroupShape = function(type) to
Expand Down
84 changes: 51 additions & 33 deletions visio/model/ooxmlApi/convertFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,38 +1172,43 @@

let localYmm;

let flipYCell = shape.getCell("FlipY");
let flipVertically = flipYCell ? flipYCell.v === "1" : false;
if (flipVertically) {
// if we flip figure we flip text pinY around shape pinY
if (txtPinY_inch > 0) {
// y cord of text block start. when cord system starts in left bottom corner on shape
let blockCord = txtPinY_inch - txtLocPinY_inch;
// (y part of vector) from shape center to txt block start
let fromShapeCenterToBlockStart = blockCord - shapeLocPinY;

// mirror distance fromBlock start ToShapeCenter then add text block height to it
// + shapeLocPinY made shift from shape center to shape bottom bcs we calculate
// localYmm starting from bottom of shape not from center
localYmm = (-fromShapeCenterToBlockStart - txtHeight_inch + shapeLocPinY) * g_dKoef_in_to_mm;
} else {
// negative, y part of vector. y cord of text block start. when cord system starts in left bottom corner on shape
let blockCord = txtPinY_inch + (txtHeight_inch - txtLocPinY_inch);
// Don't recalculate text pos on flip manually, shape with text combined to group whose flipV is applied
// let flipYCell = shape.getCell("FlipY");
// let flipVertically = flipYCell ? flipYCell.v === "1" : false;
// if (flipVertically) {
// // if we flip figure we flip text pinY around shape pinY
// if (txtPinY_inch > 0) {
// // y cord of text block start. when cord system starts in left bottom corner on shape
// let blockCord = txtPinY_inch - txtLocPinY_inch;
// // (y part of vector) from shape center to txt block start
// let fromShapeCenterToBlockStart = blockCord - shapeLocPinY;
//
// // mirror distance fromBlock start ToShapeCenter then add text block height to it
// // + shapeLocPinY made shift from shape center to shape bottom bcs we calculate
// // localYmm starting from bottom of shape not from center
// localYmm = (-fromShapeCenterToBlockStart - txtHeight_inch + shapeLocPinY) * g_dKoef_in_to_mm;
// } else {
// // negative, y part of vector. y cord of text block start. when cord system starts in left bottom corner on shape
// let blockCord = txtPinY_inch + (txtHeight_inch - txtLocPinY_inch);
//
// // lets make it negative like y part of vector. It comes from top to bottom.
// // It is vector that comes from shape center to text block start.
// let fromBlockToShapeCenter = blockCord - shapeLocPinY;
//
// // Finally we mirror fromBlockToShapeCenter by multiplying by -1 and add shapeLocPinY to move its
// // start to bottom on shape
// localYmm = (-fromBlockToShapeCenter + shapeLocPinY) * g_dKoef_in_to_mm;
// }
// oXfrm.setRot(- textAngle);
// } else {
// // do calculations
// localYmm = (txtPinY_inch - txtLocPinY_inch) * g_dKoef_in_to_mm;
// oXfrm.setRot(textAngle);
// }

// lets make it negative like y part of vector. It comes from top to bottom.
// It is vector that comes from shape center to text block start.
let fromBlockToShapeCenter = blockCord - shapeLocPinY;

// Finally we mirror fromBlockToShapeCenter by multiplying by -1 and add shapeLocPinY to move its
// start to bottom on shape
localYmm = (-fromBlockToShapeCenter + shapeLocPinY) * g_dKoef_in_to_mm;
}
oXfrm.setRot(- textAngle);
} else {
// do calculations
localYmm = (txtPinY_inch - txtLocPinY_inch) * g_dKoef_in_to_mm;
oXfrm.setRot(textAngle);
}
// do calculations
localYmm = (txtPinY_inch - txtLocPinY_inch) * g_dKoef_in_to_mm;
oXfrm.setRot(textAngle);

let offY = globalYmm + localYmm;
// back to presentation coords
Expand All @@ -1224,11 +1229,13 @@
oXfrm.setExtY(Math.abs(shapeHeight) * g_dKoef_in_to_mm);
oXfrm.setRot(0);
}

oSpPr.setXfrm(oXfrm);
oXfrm.setParent(oSpPr);
oSpPr.setFill(AscFormat.CreateNoFillUniFill());
oSpPr.setLn(AscFormat.CreateNoFillLine());


textCShape.setSpPr(oSpPr);
oSpPr.setParent(textCShape);

Expand Down Expand Up @@ -2172,8 +2179,10 @@
noLineFillSpPr.setFill(AscFormat.CreateNoFillUniFill());
noLineFillSpPr.setLn(AscFormat.CreateNoFillLine());
// these flips come to group
noLineFillSpPr.xfrm.flipV = false;
noLineFillSpPr.xfrm.flipH = false;
noLineFillSpPr.xfrm.flipV = cShape.spPr.xfrm.flipV;
noLineFillSpPr.xfrm.flipH = cShape.spPr.xfrm.flipH;
cShape.spPr.xfrm.flipV = false;
cShape.spPr.xfrm.flipH = false;

groupShape.setSpPr(noLineFillSpPr);
groupShape.spPr.setParent(groupShape);
Expand All @@ -2200,10 +2209,19 @@
textCShape.spPr.xfrm.flipH = false;
textCShape.spPr.xfrm.flipV = false;

// In power point presentations on flipV text is position is flipped + text
// is mirrored horizontally and vertically (https://disk.yandex.ru/d/Hi8OCMITgb730Q)
// below we remove text mirror. In visio text is never mirrored. (https://disk.yandex.ru/d/JjbNzzZLDIAEuQ)
// (on flipH in power point presentation text is not mirrored)
if (textCShape.getFullFlip().flipV) {
textCShape.spPr.xfrm.setRot(Math.PI + textCShape.spPr.xfrm.rot);
}

textCShape.recalculateLocalTransform(textCShape.transform);
textCShape.recalculateTransformText();
textCShape.recalculateContent();


groupShape.setParent2(visioDocument);
groupShape.recalculate();

Expand Down
18 changes: 18 additions & 0 deletions visio/model/overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ AscFormat.CShape.prototype.getParentObjects = function ()
return {slide: null, layout: null, master: null, theme: oTheme};
};

/**
* get full flip using group flips
* @return {{flipV: (boolean|*), flipH: (boolean|*)}}
*/
AscFormat.CShape.prototype.getFullFlip = function ()
{
let group = this.group;
let flipV = this.spPr.xfrm.flipV;
let flipH = this.spPr.xfrm.flipH;
while (group) {
flipV = group.spPr.xfrm.flipV ? !flipV : flipV;
flipH = group.spPr.xfrm.flipH ? !flipH : flipH;
group = group.group;
}

return {flipV: flipV, flipH: flipH};
};

/**
* @memberOf AscFormat.CGroupShape
* @type {function(): {layout: null, slide: null, theme: CTheme, master: null}}
Expand Down

0 comments on commit 87d3961

Please sign in to comment.