Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/copypaste ms inlinelevelesdt #3063

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 141 additions & 45 deletions common/wordcopypaste.js
Original file line number Diff line number Diff line change
Expand Up @@ -6509,7 +6509,7 @@ PasteProcessor.prototype =
},
_IsBlockElem: function (name) {
if ("p" === name || "div" === name || "ul" === name || "ol" === name || "li" === name || "table" === name || "tbody" === name || "tr" === name || "td" === name || "th" === name ||
"h1" === name || "h2" === name || "h3" === name || "h4" === name || "h5" === name || "h6" === name || "center" === name || "dd" === name || "dt" === name || "w:sdt" === name)
"h1" === name || "h2" === name || "h3" === name || "h4" === name || "h5" === name || "h6" === name || "center" === name || "dd" === name || "dt" === name)
return true;
return false;
},
Expand Down Expand Up @@ -8430,55 +8430,135 @@ PasteProcessor.prototype =
},

_ExecuteBlockLevelStd : function (node, pPr) {
var blockLevelSdt = new CBlockLevelSdt(this.oLogicDocument, this.oDocument);

//1. plain text (CInlineLevelSdt)
// <body lang=EN-US style='tab-interval:.5in;word-wrap:break-word'>
// <!--StartFragment-->
// <span>
// <w:Sdt DocPart="AD334DF7FD99465099BBBD9F3C3AE5AE" ID="-818574957">
// <span style='mso-spacerun:yes'>В </span>
// Plaein text
// </w:Sdt>
// </span>
// <!--EndFragment-->
// </body>


//2. Rich text (CBlockLevelSdt)
//
// <body lang=EN-US style='tab-interval:.5in;word-wrap:break-word'>
// <!--StartFragment-->
// <w:Sdt DocPart="5AAA70241BB24C68A16AC32AB3233FFC" ID="819472493">
// <p className=MsoNormal>Rich plain textf
// <o:p/>
// <w:sdtPr/>
// </p>
// </w:Sdt>
// <!--EndFragment-->
// </body>

//3.picture(CInlineLevelSdt)

// <p class=MsoNormal>
// <w:Sdt ShowingPlcHdr="t" DocPart="6BE2DA46972A420788E197A3986DD1A7" DisplayAsPicture="t" Text="t" ID="575168600">
// </span>
// </w:Sdt>
// <o:p/>
// </p>

//4. Choose (CInlineLevelSdt)

// <body lang=EN-US style='tab-interval:.5in;word-wrap:break-word'>
// <!--StartFragment-->
// <span>
// <w:Sdt ShowingPlcHdr="t" DocPart="F7011D2027BE4F6C919D5BB7D95A0DC0" DropDown="t" ID="1536853350">
// <w:ListItem ListValue="Choose an item" DataValue=""/>Choose an item
// </w:Sdt>
// </span>
// <!--EndFragment-->
// </body>


//5. Date (CInlineLevelSdt)

// <body lang=EN-US style='tab-interval:.5in;word-wrap:break-word'>
// <!--StartFragment-->
// <span>
// <w:Sdt DocPart="0D4FD865761947FCBA0D9229E17016DB" Calendar="t" MapToDateTime="t" CalendarType="Gregorian" Date="2022-10-24T20:27:00Z" DateFormat="dd.MM.yyyy" Lang="EN-US" ID="-291673853">24.10.2022</w:Sdt>
// </span>
// <!--EndFragment-->
// </body>


//6. check box (CInlineLevelSdt)
//
// <body lang=EN-US style='tab-interval:.5in;word-wrap:break-word'>
// <!--StartFragment-->
// <span>
// <w:Sdt CheckBox="t" CheckBoxIsChecked="t" CheckBoxValueChecked="☒" CheckBoxValueUnchecked="☐" CheckBoxFontChecked="MS Gothic" CheckBoxFontUnchecked="MS Gothic" ID="-213812918">
// <span style='font-family:
// "MS Gothic"'>☒</span>
// </w:Sdt>
// </span>
// <!--EndFragment-->
// </body>




//w:Sdt -> ориентируемся по первому внутреннему тегу
//если параграф - то оборачиваем в CBlockLevelSdt, если текст с настройками - в CInlineLevelSdt
let isBlockLevelSdt = node.getElementsByTagName("p").length > 0;
let levelSdt = isBlockLevelSdt ? new CBlockLevelSdt(this.oLogicDocument, this.oDocument) : new CInlineLevelSdt();

//ms в буфер записывает только lock контента
let checkBox, dropdown, comboBox;
if (node && node.attributes) {
var contentLocked = node.attributes["contentlocked"];
let contentLocked = node.attributes["contentlocked"];
if (contentLocked /*&& contentLocked.value === "t"*/) {
blockLevelSdt.SetContentControlLock(c_oAscSdtLockType.SdtContentLocked);
levelSdt.SetContentControlLock(c_oAscSdtLockType.SdtContentLocked);
}
//далее тег и титульник, цвета нет
var alias = node.attributes["title"];
let alias = node.attributes["title"];
if (alias && alias.value) {
blockLevelSdt.SetAlias(alias.value);
levelSdt.SetAlias(alias.value);
}
var tag = node.attributes["sdttag"];
let tag = node.attributes["sdttag"];
if (tag && tag.value) {
blockLevelSdt.SetTag(tag.value);
levelSdt.SetTag(tag.value);
}
var temporary = node.attributes["temporary"];
let temporary = node.attributes["temporary"];
if (temporary && temporary.value) {
blockLevelSdt.SetContentControlTemporary(temporary.value === "t");
levelSdt.SetContentControlTemporary(temporary.value === "t");
}

var placeHolder = node.attributes["showingplchdr"];
let placeHolder = node.attributes["showingplchdr"];
if (placeHolder && placeHolder.value === "t") {
blockLevelSdt.SetPlaceholder(c_oAscDefaultPlaceholderName.Text);
levelSdt.SetPlaceholder(c_oAscDefaultPlaceholderName.Text);
}

//TODO поддержать Picture CC
/*var aspicture = node.attributes["displayaspicture"];
/*let aspicture = node.attributes["displayaspicture"];
if (aspicture) {
blockLevelSdt.SetPicturePr(aspicture.value === "t");
}*/


var getCharCode = function (text) {
var charCode;
for (var oIterator = text.getUnicodeIterator(); oIterator.check(); oIterator.next()) {
let getCharCode = function (text) {
let charCode;
for (let oIterator = text.getUnicodeIterator(); oIterator.check(); oIterator.next()) {
charCode = oIterator.value();
}
return charCode;
};

var setListItems = function (addFunc) {
for (var i = 0, length = node.childNodes.length; i < length; i++) {
var child = node.childNodes[i];
let setListItems = function (addFunc) {
for (let i = 0, length = node.childNodes.length; i < length; i++) {
let child = node.childNodes[i];
if (child && "w:listitem" === child.nodeName.toLowerCase()) {
if (child.attributes) {
var listvalue = child.attributes["listvalue"] && child.attributes["listvalue"].value;
var datavalue = child.attributes["datavalue"] && child.attributes["datavalue"].value;
let listvalue = child.attributes["listvalue"] && child.attributes["listvalue"].value;
let datavalue = child.attributes["datavalue"] && child.attributes["datavalue"].value;
if (datavalue) {
addFunc(datavalue, listvalue ? listvalue : undefined);
}
Expand All @@ -8487,45 +8567,45 @@ PasteProcessor.prototype =
}
};

var oPr;
var checkBox = node.attributes["checkbox"];
let oPr;
checkBox = node.attributes["checkbox"];
if (checkBox && checkBox.value === "t") {
oPr = new AscWord.CSdtCheckBoxPr();
var checked = node.attributes["checkboxischecked"];
let checked = node.attributes["checkboxischecked"];
if (checked) {
oPr.Checked = checked.value === "t";
}
var checkedFont = node.attributes["checkboxfontchecked"];
let checkedFont = node.attributes["checkboxfontchecked"];
if (checkedFont) {
oPr.CheckedFont = checkedFont.value;
}
var checkedSymbol = node.attributes["checkboxvaluechecked"];
let checkedSymbol = node.attributes["checkboxvaluechecked"];
if (checkedSymbol) {
oPr.CheckedSymbol = getCharCode(checkedSymbol.value);
}
var uncheckedFont = node.attributes["checkboxfontunchecked"];
let uncheckedFont = node.attributes["checkboxfontunchecked"];
if (uncheckedFont) {
oPr.UncheckedFont = uncheckedFont.value;
}
var uncheckedSymbol = node.attributes["checkboxvalueunchecked"];
let uncheckedSymbol = node.attributes["checkboxvalueunchecked"];
if (checkedSymbol) {
oPr.UncheckedSymbol = getCharCode(uncheckedSymbol.value);
}

blockLevelSdt.ApplyCheckBoxPr(oPr);
levelSdt.ApplyCheckBoxPr(oPr);
}

var id = node.attributes["id"];
let id = node.attributes["id"];
if (id) {
blockLevelSdt.Pr.Id = id;
levelSdt.Pr.Id = id;
}

var comboBox = node.attributes["combobox"];
comboBox = node.attributes["combobox"];
if (comboBox && comboBox.value === "t") {
oPr = new AscWord.CSdtComboBoxPr();
}

var dropdown = node.attributes["dropdown"];
dropdown = node.attributes["dropdown"];
if (dropdown && dropdown.value === "t") {
oPr = new AscWord.CSdtComboBoxPr();
}
Expand All @@ -8536,40 +8616,55 @@ PasteProcessor.prototype =
setListItems(function (sDisplay, sValue) {
oPr.AddItem(sDisplay, sValue);
});
blockLevelSdt.ApplyComboBoxPr(oPr);
levelSdt.ApplyComboBoxPr(oPr);
}
}

//content
if (!checkBox && !comboBox && !dropdown) {
var oPasteProcessor = new PasteProcessor(this.api, false, false, true);
let oPasteProcessor = new PasteProcessor(this.api, false, false, true);
oPasteProcessor.AddedFootEndNotes = this.AddedFootEndNotes;
oPasteProcessor.msoComments = this.msoComments;
oPasteProcessor.oFonts = this.oFonts;
oPasteProcessor.oImages = this.oImages;
oPasteProcessor.bIsForFootEndnote = this.bIsForFootEndnote;
oPasteProcessor.oDocument = blockLevelSdt.Content;
oPasteProcessor.oDocument = isBlockLevelSdt ? levelSdt.Content : this.oDocument;
oPasteProcessor.bIgnoreNoBlockText = true;
oPasteProcessor.aMsoHeadStylesStr = this.aMsoHeadStylesStr;
oPasteProcessor.oMsoHeadStylesListMap = this.oMsoHeadStylesListMap;
oPasteProcessor.msoListMap = this.msoListMap;
oPasteProcessor._Execute(node, pPr, true, true, false);
oPasteProcessor._PrepareContent();
oPasteProcessor._AddNextPrevToContent(blockLevelSdt.Content);
oPasteProcessor._AddNextPrevToContent(levelSdt.Content);

//добавляем новый параграфы
for (var i = 0, length = oPasteProcessor.aContent.length; i < length; ++i) {
if (i === length - 1) {
blockLevelSdt.Content.Internal_Content_Add(i + 1, oPasteProcessor.aContent[i], true);
} else {
blockLevelSdt.Content.Internal_Content_Add(i + 1, oPasteProcessor.aContent[i], false);
let i, j, length, length2;
if (isBlockLevelSdt) {
for (i = 0, length = oPasteProcessor.aContent.length; i < length; ++i) {
if (i === length - 1) {
levelSdt.Content.Internal_Content_Add(i + 1, oPasteProcessor.aContent[i], true);
} else {
levelSdt.Content.Internal_Content_Add(i + 1, oPasteProcessor.aContent[i], false);
}
}
levelSdt.Content.Internal_Content_Remove(0, 1);
} else {
for (i = 0, length = oPasteProcessor.aContent.length; i < length; ++i) {
if (oPasteProcessor.aContent[i] && oPasteProcessor.aContent[i].Content) {
for (j = 0, length2 = oPasteProcessor.aContent[i].Content.length - 1; j < length2; ++j) {
levelSdt.AddToContent(j, oPasteProcessor.aContent[i].Content[j]);
}
}
}
}

blockLevelSdt.Content.Internal_Content_Remove(0, 1);
}

this.aContent.push(blockLevelSdt);
if (isBlockLevelSdt) {
this.aContent.push(levelSdt);
} else {
this._CommitElemToParagraph(levelSdt);
this.oCur_rPr = new CTextPr();
}
},

_ExecuteBorder: function (computedStyle, node, type, type2, bAddIfNull, setUnifill) {
Expand Down Expand Up @@ -10039,6 +10134,7 @@ PasteProcessor.prototype =

if ("w:sdt" === sNodeName && this.pasteInExcel !== true && this.pasteInPresentationShape !== true) {
//CBlockLevelSdt
bAddParagraph = this._Decide_AddParagraph(node, pPr, bAddParagraph);
this._ExecuteBlockLevelStd(node, pPr);
return bAddParagraph;
}
Expand Down
3 changes: 2 additions & 1 deletion word/Editor/Serialize2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8382,9 +8382,10 @@ function BinaryFileReader(doc, openParams)
if (docProtection) {
//this.Document.applyProtection()
var restrictionType = docProtection.getRestrictionType();
var enforcement = docProtection.getEnforcement();
if (/*docProtection.isOnlyView() && false !== docProtection.getEnforcement()*/restrictionType !== null) {
api && api.asc_addRestriction(restrictionType);
} else if (false !== docProtection.getEnforcement() ) {
} else if (false !== enforcement && enforcement != null && restrictionType !== null) {
//TODO ?
api && api.asc_addRestriction(Asc.c_oAscRestrictionType.View);
}
Expand Down