feat: 支持文本段落首行缩进(#112)

This commit is contained in:
pipipi-pikachu 2022-05-28 14:58:27 +08:00
parent 533b76ffee
commit 6f087bfe97
5 changed files with 29 additions and 1 deletions

View File

@ -15,6 +15,10 @@
color: inherit; color: inherit;
} }
p {
text-indent: var(--textIndent);
}
p + p { p + p {
margin-top: 5px; margin-top: 5px;
} }

View File

@ -141,6 +141,7 @@ export interface PPTTextElement extends PPTBaseElement {
wordSpace?: number; wordSpace?: number;
opacity?: number; opacity?: number;
shadow?: PPTElementShadow; shadow?: PPTElementShadow;
textIndent?: number;
} }

View File

@ -234,6 +234,13 @@
<SelectOption v-for="item in wordSpaceOptions" :key="item" :value="item">{{item}}px</SelectOption> <SelectOption v-for="item in wordSpaceOptions" :key="item" :value="item">{{item}}px</SelectOption>
</Select> </Select>
</div> </div>
<div class="row">
<div style="flex: 2;">首行缩进</div>
<Select style="flex: 3;" :value="textIndent" @change="value => updateTextIndent(value)">
<template #suffixIcon><IconIndentRight /></template>
<SelectOption v-for="item in textIndentOptions" :key="item" :value="item">{{item}}px</SelectOption>
</Select>
</div>
<div class="row"> <div class="row">
<div style="flex: 2;">文本框填充</div> <div style="flex: 2;">文本框填充</div>
<Popover trigger="click"> <Popover trigger="click">
@ -368,6 +375,7 @@ export default defineComponent({
const fill = ref<string>() const fill = ref<string>()
const lineHeight = ref<number>() const lineHeight = ref<number>()
const wordSpace = ref<number>() const wordSpace = ref<number>()
const textIndent = ref<number>()
watch(handleElement, () => { watch(handleElement, () => {
if (!handleElement.value || handleElement.value.type !== 'text') return if (!handleElement.value || handleElement.value.type !== 'text') return
@ -375,6 +383,7 @@ export default defineComponent({
fill.value = handleElement.value.fill || '#fff' fill.value = handleElement.value.fill || '#fff'
lineHeight.value = handleElement.value.lineHeight || 1.5 lineHeight.value = handleElement.value.lineHeight || 1.5
wordSpace.value = handleElement.value.wordSpace || 0 wordSpace.value = handleElement.value.wordSpace || 0
textIndent.value = handleElement.value.textIndent || 0
}, { deep: true, immediate: true }) }, { deep: true, immediate: true })
const fontSizeOptions = [ const fontSizeOptions = [
@ -384,6 +393,7 @@ export default defineComponent({
] ]
const lineHeightOptions = [0.9, 1.0, 1.15, 1.2, 1.4, 1.5, 1.8, 2.0, 2.5, 3.0] const lineHeightOptions = [0.9, 1.0, 1.15, 1.2, 1.4, 1.5, 1.8, 2.0, 2.5, 3.0]
const wordSpaceOptions = [0, 1, 2, 3, 4, 5, 6, 8, 10] const wordSpaceOptions = [0, 1, 2, 3, 4, 5, 6, 8, 10]
const textIndentOptions = [0, 48, 96, 144, 192, 240, 288, 336]
// //
const updateLineHeight = (value: number) => { const updateLineHeight = (value: number) => {
@ -395,6 +405,11 @@ export default defineComponent({
updateElement({ wordSpace: value }) updateElement({ wordSpace: value })
} }
//
const updateTextIndent = (value: number) => {
updateElement({ textIndent: value })
}
// //
const updateFill = (value: string) => { const updateFill = (value: string) => {
updateElement({ fill: value }) updateElement({ fill: value })
@ -433,14 +448,17 @@ export default defineComponent({
fill, fill,
lineHeight, lineHeight,
wordSpace, wordSpace,
textIndent,
richTextAttrs, richTextAttrs,
availableFonts, availableFonts,
webFonts, webFonts,
fontSizeOptions, fontSizeOptions,
lineHeightOptions, lineHeightOptions,
wordSpaceOptions, wordSpaceOptions,
textIndentOptions,
updateLineHeight, updateLineHeight,
updateWordSpace, updateWordSpace,
updateTextIndent,
updateFill, updateFill,
emitRichTextCommand, emitRichTextCommand,
emitBatchRichTextCommand, emitBatchRichTextCommand,

View File

@ -28,7 +28,11 @@
:height="elementInfo.height" :height="elementInfo.height"
:outline="elementInfo.outline" :outline="elementInfo.outline"
/> />
<div class="text ProseMirror-static" v-html="elementInfo.content"></div> <div
class="text ProseMirror-static"
:style="{ '--textIndent': `${elementInfo.textIndent || 0}px` }"
v-html="elementInfo.content"
></div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -39,6 +39,7 @@
:defaultFontName="elementInfo.defaultFontName" :defaultFontName="elementInfo.defaultFontName"
:editable="!elementInfo.lock" :editable="!elementInfo.lock"
:value="elementInfo.content" :value="elementInfo.content"
:style="{ '--textIndent': `${elementInfo.textIndent || 0}px` }"
@update="value => updateContent(value)" @update="value => updateContent(value)"
@blur="checkEmptyText()" @blur="checkEmptyText()"
@mousedown="$event => handleSelectElement($event, false)" @mousedown="$event => handleSelectElement($event, false)"