improve: adaptive size when the image is larger than the page width #599
This commit is contained in:
@@ -1796,14 +1796,15 @@ export class CommandAdapt {
|
|||||||
if (isDisabled) return
|
if (isDisabled) return
|
||||||
const { startIndex, endIndex } = this.range.getRange()
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
if (!~startIndex && !~endIndex) return
|
if (!~startIndex && !~endIndex) return
|
||||||
const { value, width, height } = payload
|
const { value, width, height, imgDisplay } = payload
|
||||||
this.insertElementList([
|
this.insertElementList([
|
||||||
{
|
{
|
||||||
value,
|
value,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
id: getUUID(),
|
id: getUUID(),
|
||||||
type: ElementType.IMAGE
|
type: ElementType.IMAGE,
|
||||||
|
imgDisplay
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@@ -1995,12 +1996,12 @@ export class CommandAdapt {
|
|||||||
public changeImageDisplay(element: IElement, display: ImageDisplay) {
|
public changeImageDisplay(element: IElement, display: ImageDisplay) {
|
||||||
if (element.imgDisplay === display) return
|
if (element.imgDisplay === display) return
|
||||||
element.imgDisplay = display
|
element.imgDisplay = display
|
||||||
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
if (
|
if (
|
||||||
display === ImageDisplay.FLOAT_TOP ||
|
display === ImageDisplay.FLOAT_TOP ||
|
||||||
display === ImageDisplay.FLOAT_BOTTOM
|
display === ImageDisplay.FLOAT_BOTTOM
|
||||||
) {
|
) {
|
||||||
const positionList = this.position.getPositionList()
|
const positionList = this.position.getPositionList()
|
||||||
const { startIndex } = this.range.getRange()
|
|
||||||
const {
|
const {
|
||||||
coordinate: { leftTop }
|
coordinate: { leftTop }
|
||||||
} = positionList[startIndex]
|
} = positionList[startIndex]
|
||||||
@@ -2013,7 +2014,8 @@ export class CommandAdapt {
|
|||||||
}
|
}
|
||||||
this.draw.getPreviewer().clearResizer()
|
this.draw.getPreviewer().clearResizer()
|
||||||
this.draw.render({
|
this.draw.render({
|
||||||
isSetCursor: false
|
isSetCursor: true,
|
||||||
|
curIndex: endIndex
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1199,21 +1199,13 @@ export class Draw {
|
|||||||
} else {
|
} else {
|
||||||
const elementWidth = element.width! * scale
|
const elementWidth = element.width! * scale
|
||||||
const elementHeight = element.height! * scale
|
const elementHeight = element.height! * scale
|
||||||
// 图片超出尺寸后自适应
|
// 图片超出尺寸后自适应(图片大小大于可用宽度时)
|
||||||
const curRowWidth =
|
if (elementWidth > availableWidth) {
|
||||||
element.imgDisplay === ImageDisplay.INLINE ? 0 : curRow.width
|
|
||||||
if (curRowWidth + elementWidth > availableWidth) {
|
|
||||||
// 计算剩余大小
|
|
||||||
const surplusWidth = availableWidth - curRowWidth
|
|
||||||
const adaptiveWidth =
|
|
||||||
surplusWidth > 0
|
|
||||||
? surplusWidth
|
|
||||||
: Math.min(elementWidth, availableWidth)
|
|
||||||
const adaptiveHeight =
|
const adaptiveHeight =
|
||||||
(elementHeight * adaptiveWidth) / elementWidth
|
(elementHeight * availableWidth) / elementWidth
|
||||||
element.width = adaptiveWidth / scale
|
element.width = availableWidth / scale
|
||||||
element.height = adaptiveHeight / scale
|
element.height = adaptiveHeight / scale
|
||||||
metrics.width = adaptiveWidth
|
metrics.width = availableWidth
|
||||||
metrics.height = adaptiveHeight
|
metrics.height = adaptiveHeight
|
||||||
metrics.boundingBoxDescent = adaptiveHeight
|
metrics.boundingBoxDescent = adaptiveHeight
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export interface IDrawImagePayload {
|
|||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
value: string
|
value: string
|
||||||
|
imgDisplay?: ImageDisplay
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDrawRowPayload {
|
export interface IDrawRowPayload {
|
||||||
|
|||||||
Reference in New Issue
Block a user