Skip to content

Commit

Permalink
[ve] Add themeval font cell calculation (set Calibri for default them…
Browse files Browse the repository at this point in the history
…e); Fix bug 72727
  • Loading branch information
fedek1324 committed Feb 10, 2025
1 parent 6f1f96c commit e845557
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
33 changes: 16 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 @@ -1808,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 Down
2 changes: 1 addition & 1 deletion visio/model/ooxmlApi/ooxmlApiIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,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
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 e845557

Please sign in to comment.