Skip to content

Commit

Permalink
Merge pull request 'feature/visio' (#649) from feature/visio into dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Feb 10, 2025
2 parents fa1d1fd + e845557 commit cb4eb64
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 32 deletions.
1 change: 1 addition & 0 deletions visio/model/VisioDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@
let pageContent = this.pageContents[pageIndex];

if (!this.backgroundAppliedFor.includes(pageIndex)) {
this.backgroundAppliedFor.push(pageIndex);
let backgroundPageId = pageInfo.backPage;
if (backgroundPageId !== null && backgroundPageId !== undefined) {
// find background page
Expand Down
73 changes: 56 additions & 17 deletions visio/model/ooxmlApi/convertFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@
* @param {number} maxHeightScaledIn
* @param {number} currentPageIndex
* @param {number} pagesCount
* @param {Page_Type} pageInfo
* @return {CShape} textCShape
*/
function getTextCShape(theme, shape, cShape, lineUniFill,
fillUniFill, drawingPageScale, maxHeightScaledIn, currentPageIndex, pagesCount ) {
fillUniFill, drawingPageScale, maxHeightScaledIn, currentPageIndex, pagesCount, pageInfo) {
// see 2.2.8 Text [MS-VSDX]-220215
/**
* handle QuickStyleVariation cell which can change color (but only if color is a result of ThemeVal)
Expand Down Expand Up @@ -241,7 +242,7 @@
Math.abs(backgroundColorHSL.L - fillColorHSL.L) >
Math.abs(backgroundColorHSL.L - lineColorHSL.L) &&
Math.abs(backgroundColorHSL.L - fillColorHSL.L) >
Math.abs(backgroundColorHSL.L - textColorHSL.L);
Math.abs(backgroundColorHSL.L - textColorHSL.L);
if (fillDifferenceIsTheLargest) {
textColorRGBA.R = fillColorRGBA.R;
textColorRGBA.G = fillColorRGBA.G;
Expand Down Expand Up @@ -417,9 +418,10 @@
* @param theme
* @param shape
* @param visioDocument
* @param {Page_Type} pageInfo
*/
function setRunProps(characterRowNum, characterPropsCommon, oRun, lineUniFill,
fillUniFill, theme, shape, visioDocument) {
fillUniFill, theme, shape, visioDocument, pageInfo) {
let characterPropsFinal = characterRowNum !== null && characterPropsCommon.getRow(characterRowNum);

/**
Expand Down Expand Up @@ -532,16 +534,12 @@
let fontCell = characterPropsFinal && characterPropsFinal.getCell("Font");
let cRFonts = new CRFonts();
if (fontCell && fontCell.kind === AscVisio.c_oVsdxSheetStorageKind.Cell_Type) {
// let fontColor = calculateCellValue(theme, shape, characterColorCell);

// all document fonts all loaded already in CVisioDocument.prototype.loadFonts
let fontName = fontCell.v;
if (fontName !== "Themed") {
cRFonts = getRFonts(fontName, visioDocument);
} else {
let themeFontName = theme.getFontScheme().majorFont.latin;
cRFonts = getRFonts(themeFontName, visioDocument);
}

let fontName = fontCell.calculateValue(shape, pageInfo,
visioDocument.themes, themeValWasUsedFor, true);

cRFonts = getRFonts(fontName, visioDocument);
} else {
AscCommon.consoleLog("fontCell was not found so default is set (Calibri). Check mb AsianFont or ScriptFont");
}
Expand Down Expand Up @@ -586,6 +584,7 @@
const valueCell = fieldRow.getCell("Value");
oFld.SetFieldType(valueCell.f);
oFld.vsdxFieldValue = valueCell;
// inits new class variable
oFld.isTextInherited = isTextInherited;

// then format it according to Format cell
Expand Down Expand Up @@ -852,7 +851,7 @@

setRunProps(characterRowNum, characterPropsCommon,
oRun, lineUniFill, fillUniFill, theme, shape,
visioDocument);
visioDocument, pageInfo);
paragraph.Add_ToContent(paragraph.Content.length - 1, oRun);
} else if (textElementPart.kind === AscVisio.c_oVsdxTextKind.FLD) {
// text field
Expand All @@ -879,7 +878,7 @@

setRunProps(characterRowNum, characterPropsCommon,
oFld, lineUniFill, fillUniFill, theme, shape,
visioDocument);
visioDocument, pageInfo);

paragraph.AddToContent(paragraph.Content.length - 1, new ParaRun(paragraph, false));
paragraph.AddToContent(paragraph.Content.length - 1, oFld);
Expand Down Expand Up @@ -1117,7 +1116,7 @@
oXfrm.setExtY(Math.abs(shapeHeight) * g_dKoef_in_to_mm);
oXfrm.setRot(0);
}
oSpPr.setXfrm(oXfrm);
oSpPr.setXfrm(oXfrm);
oXfrm.setParent(oSpPr);
oSpPr.setFill(AscFormat.CreateNoFillUniFill());
oSpPr.setLn(AscFormat.CreateNoFillLine());
Expand Down Expand Up @@ -1515,7 +1514,7 @@
let gradientEnabled;
if (gradientEnabledCell !== undefined) {
gradientEnabled = gradientEnabledCell.calculateValue(this, pageInfo,
visioDocument.themes, themeValWasUsedFor, true);
visioDocument.themes, themeValWasUsedFor, true);
} else {
gradientEnabled = false;
}
Expand Down Expand Up @@ -1579,6 +1578,10 @@
colorStop.setPos(pos);

fillGradientStops.push({Gs : colorStop});

if ((pos === 100000 && !invertGradient) || (invertGradient && pos === 0)) {
break;
}
}

if (fillGradientDir === 3) {
Expand Down Expand Up @@ -1804,7 +1807,7 @@
// not scaling fontSize
let textCShape = getTextCShape(visioDocument.themes[0], this, cShape,
lineUniFill, uniFillForegnd, drawingPageScale, maxHeightScaledIn,
visioDocument.pageIndex, visioDocument.pages.page.length);
visioDocument.pageIndex, visioDocument.pages.page.length, pageInfo);

if (textCShape !== null) {
if (isShapeDeleted) {
Expand All @@ -1826,6 +1829,40 @@
this.cImageShape.setBDeleted(false);
this.cImageShape.setSpPr(cShape.spPr.createDuplicate());
this.cImageShape.spPr.setParent(this.cImageShape);

let imgWidth_inch = this.getCellNumberValueWithScale("ImgWidth", drawingPageScale);
let imgHeight_inch = this.getCellNumberValueWithScale("ImgHeight", drawingPageScale);
let imgOffsetX_inch = this.getCellNumberValueWithScale("ImgOffsetX", drawingPageScale);
let imgOffsetY_inch = this.getCellNumberValueWithScale("ImgOffsetY", drawingPageScale);

let imgWidth_mm = imgWidth_inch * g_dKoef_in_to_mm;
let imgHeight_mm = imgHeight_inch * g_dKoef_in_to_mm;

this.cImageShape.blipFill.srcRect = new AscFormat.CSrcRect();
let rect = this.cImageShape.blipFill.srcRect;

if (imgWidth_inch !== undefined && imgHeight_inch !== undefined) {
let widthScale = imgWidth_mm / shapeWidth_mm;
let heightScale = imgHeight_mm / shapeHeight_mm;
// coords in our class CSrcRect is srcRect relative i.e. relative to original image size
// isInvertCoords check?
// add scale
rect.setLTRB(0, 100 - 1/heightScale * 100, 1/widthScale * 100, 100);
}
if (imgOffsetX_inch !== undefined) {
let imgOffsetX_mm = imgOffsetX_inch * g_dKoef_in_to_mm;
let offsetX = imgOffsetX_mm / imgWidth_mm;
// add horizontal shift
rect.setLTRB(rect.l - offsetX * 100, rect.t, rect.r - offsetX * 100, rect.b);
}
if (imgOffsetY_inch !== undefined) {
let imgOffsetY_mm = imgOffsetY_inch * g_dKoef_in_to_mm;
let offsetY = imgOffsetY_mm / imgHeight_mm;
// add vertical shift
rect.setLTRB(rect.l, rect.t + offsetY * 100, rect.r, rect.b + offsetY * 100);
}


this.cImageShape.rot = cShape.rot;
// this.cImageShape.brush = cShape.brush;
this.cImageShape.bounds = cShape.bounds;
Expand All @@ -1837,6 +1874,8 @@

this.cImageShape.setParent2(visioDocument);
this.cImageShape.recalculate();
this.cImageShape.recalculateTransformText && this.cImageShape.recalculateTransformText();
this.cImageShape.recalculateContent && this.cImageShape.recalculateContent();

cShape = this.cImageShape;
} else {
Expand Down
5 changes: 2 additions & 3 deletions visio/model/ooxmlApi/ooxmlApiIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
*/
function Text_Type() {
/**
* if text is inherited so we consider that text fields in it have wrong values,
* and we recalculate values them
* if text is inherited (for calculate presentation field)
*/
this.isInherited = false;

Expand Down Expand Up @@ -761,7 +760,7 @@
let fillColorResultCells = ["Color", "GradientStopColor"];
let numberResultCells = ["LinePattern", "LineWeight", "GradientStopColorTrans", "GradientStopPosition",
"FillGradientAngle", "EndArrowSize", "BeginArrowSize", "FillPattern", "LineCap"];
let stringResultCells = ["EndArrow", "BeginArrow"];
let stringResultCells = ["EndArrow", "BeginArrow", "Font"];
let booleanResultCells = ["FillGradientEnabled"];

// TODO handle 2.2.7.5 Fixed Theme
Expand Down
34 changes: 22 additions & 12 deletions visio/model/overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ AscCommon.CShapeDrawer.prototype.ds = function()

function parseFieldPictureFormat(vsdxFieldValue, vsdxFieldFormat) {
let res = "@";
if (vsdxFieldFormat.f) {
if (vsdxFieldFormat.f && vsdxFieldFormat.f !== "Inh") {
let formatFunction = vsdxFieldFormat.f.toUpperCase();
let vFieldPicture = parseInt(formatFunction.substring('FIELDPICTURE('.length));

Expand Down Expand Up @@ -670,6 +670,9 @@ AscCommonWord.CPresentationField.prototype.private_GetString = function()
{
//todo add num formats with units in editor

// now it works like if field function is not CREATOR or PAGECOUNT or it's now simple override value
// take values from text tag despite it is inherited or not

// return; returns direct tag value
// if (!this.isTextInherited) {
// return;
Expand All @@ -692,6 +695,8 @@ AscCommonWord.CPresentationField.prototype.private_GetString = function()
valueInProperUnits = Number(valueV) * g_dKoef_in_to_mm / 10;
} else if (valueUnits === "MM") {
valueInProperUnits = Number(valueV) * g_dKoef_in_to_mm;
} else if (valueUnits === "M") {
valueInProperUnits = Number(valueV) * g_dKoef_in_to_mm / 1000;
} else {
valueInProperUnits = valueV;
}
Expand Down Expand Up @@ -735,11 +740,12 @@ AscCommonWord.CPresentationField.prototype.private_GetString = function()
val = logicDocument.getCountPages();
}
}
else if("PAGENUMBER()" === sFieldType) {
if (logicDocument) {
val = logicDocument.getCurrentPage();
}
}
// else if("PAGENUMBER()" === sFieldType) {
// todo add recalculate on page load
// if (logicDocument) {
// val = logicDocument.getCurrentPage();
// }
// }
// else if("NOW()" === sFieldType)
// {
// let oDateTime = new Asc.cDate();
Expand All @@ -761,13 +767,17 @@ AscCommonWord.CPresentationField.prototype.private_GetString = function()
val = logicDocument.core.creator;
}
}
else if("WIDTH" === sFieldType)
{
//todo display units
val = this.vsdxFieldValue.getValueInMM();
}
else if ((this.vsdxFieldValue.u === "STR" || !this.vsdxFieldValue.u) && (sFieldType === "INH" || !sFieldType)) {
// else if("WIDTH" === sFieldType)
// {
// //todo display units
// //leave value
// }
else if ((this.vsdxFieldValue.u === "STR" || !this.vsdxFieldValue.u) && (sFieldType === "INH" || !sFieldType)
&& !this.vsdxFieldFormat) {
// else if (this.vsdxFieldValue.u === "STR" && (sFieldType === "INH" || !sFieldType)) {
// handle simple values. consider is function is INH value is calculated correctly already
// like
// <Cell N='Value' V='1' F='Inh'/>
val = this.vsdxFieldValue.v;
}
else
Expand Down
15 changes: 15 additions & 0 deletions visio/model/visioFunctionsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@
isFillIdx = true;

initialDefaultValue = 1; // number is return type in calculateValue. Solid fill.
} else if (cellName === "Font") {
// // uses other mechanism
// quickStyleCellName = null;
// quickStyleModifiersCellName = "QuickStyleFillMatrix";
// getModifiersMethod = themes[0].getFillProp;
// isFillIdx = true;

initialDefaultValue = "Calibri";
} else {
AscCommon.consoleLog("themeval argument error. cell name: " + cellName + " is unknown. return undefined.");
return undefined;
Expand Down Expand Up @@ -474,6 +482,13 @@
}
}

if (isNaN(quickStyleColor) && isNaN(quickStyleMatrix)) {
// other mechanism for theme value calculate is used
if (cellName === "Font") {
result = theme.getFontScheme().majorFont.latin;
}
}

/**
* calculate exact color on theme. for quickStyleVariation to consider real color
* @param {CUniColor | CUniFill} color
Expand Down

0 comments on commit cb4eb64

Please sign in to comment.