devexpress-richedit
Version:
DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.
57 lines (56 loc) • 3.63 kB
JavaScript
import { ParagraphLineSpacingType, ParagraphPropertyDescriptor } from '../../../../../../../common/model/paragraph/paragraph-properties';
import { Constants } from '@devexpress/utils/lib/constants';
import { WordProcessingMLValue } from '../../../../translation-table/word-processing-mlvalue';
import { ParagraphFormattingLeafElementDestination } from '../paragraph-formatting-leaf-element-destination';
export class ParagraphSpacingDestination extends ParagraphFormattingLeafElementDestination {
async processElementOpen(reader) {
const spacingAfter = this.data.readerHelper.getWpSTIntegerValue(reader, 'after', Constants.MIN_SAFE_INTEGER);
if (spacingAfter >= 0)
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.spacingAfter, spacingAfter);
const spacingBefore = this.data.readerHelper.getWpSTIntegerValue(reader, 'before', Constants.MIN_SAFE_INTEGER);
if (spacingBefore >= 0)
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.spacingBefore, spacingBefore);
const beforeAutoSpacing = this.data.readerHelper.getWpSTOnOffValue(reader, 'beforeAutospacing', null);
if (spacingBefore == -1 || beforeAutoSpacing != null)
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.beforeAutoSpacing, spacingBefore == -1 || beforeAutoSpacing);
const afterAutoSpacing = this.data.readerHelper.getWpSTOnOffValue(reader, 'afterAutospacing', null);
if (spacingAfter == -1 || afterAutoSpacing != null)
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.afterAutoSpacing, spacingAfter == -1 || afterAutoSpacing);
const lineSpacing = this.data.readerHelper.getWpSTIntegerValue(reader, 'line', Constants.MIN_SAFE_INTEGER);
if (lineSpacing != Constants.MIN_SAFE_INTEGER && lineSpacing > 0) {
const attribute = new WordProcessingMLValue('lineRule', 'line-rule');
const lineSpacingRule = reader.getAttributeNS(attribute.openXmlValue, this.data.constants.wordProcessingNamespaceConst);
this.applyLineSpacingValue(lineSpacing, lineSpacingRule);
}
else if (lineSpacing != Constants.MIN_SAFE_INTEGER)
this.setProperty(ParagraphLineSpacingType.Single);
}
getDescriptor() {
return ParagraphPropertyDescriptor.lineSpacingType;
}
applyLineSpacingValue(lineSpacing, lineSpacingRule) {
switch (lineSpacingRule) {
case 'at-least':
case 'atLeast':
this.setProperty(ParagraphLineSpacingType.AtLeast);
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.lineSpacing, lineSpacing);
break;
case 'exact':
this.setProperty(ParagraphLineSpacingType.Exactly);
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.lineSpacing, lineSpacing);
break;
default:
if (lineSpacing == 240)
this.setProperty(ParagraphLineSpacingType.Single);
else if (lineSpacing == 360)
this.setProperty(ParagraphLineSpacingType.Sesquialteral);
else if (lineSpacing == 480)
this.setProperty(ParagraphLineSpacingType.Double);
else {
this.setProperty(ParagraphLineSpacingType.Multiple);
this.paragraphProperties.setValue(ParagraphPropertyDescriptor.lineSpacing, lineSpacing / 240.0);
}
break;
}
}
}