-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from idrawjs/dev-v0.4
feat: improve image render
- Loading branch information
Showing
12 changed files
with
268 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,57 @@ | ||
import type { Element, RendererDrawElementOptions, ViewContext2D } from '@idraw/types'; | ||
import { rotateElement } from '@idraw/util'; | ||
import { createColorStyle } from './color'; | ||
import { drawBoxShadow } from './base'; | ||
|
||
export function drawCircle(ctx: ViewContext2D, elem: Element<'circle'>, opts: RendererDrawElementOptions) { | ||
const { detail, angle } = elem; | ||
const { background = '#000000', borderColor = '#000000', borderWidth = 0 } = detail; | ||
const { calculator, viewScaleInfo, viewSizeInfo } = opts; | ||
// const { scale, offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo; | ||
const { x, y, w, h } = calculator.elementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, viewScaleInfo, viewSizeInfo); | ||
const viewElem = { ...elem, ...{ x, y, w, h, angle } }; | ||
|
||
rotateElement(ctx, { x, y, w, h, angle }, () => { | ||
const a = w / 2; | ||
const b = h / 2; | ||
const centerX = x + a; | ||
const centerY = y + b; | ||
drawBoxShadow(ctx, viewElem, { | ||
viewScaleInfo, | ||
viewSizeInfo, | ||
renderContent: () => { | ||
const a = w / 2; | ||
const b = h / 2; | ||
const centerX = x + a; | ||
const centerY = y + b; | ||
|
||
if (elem?.detail?.opacity !== undefined && elem?.detail?.opacity >= 0) { | ||
ctx.globalAlpha = elem.detail.opacity; | ||
} else { | ||
ctx.globalAlpha = 1; | ||
} | ||
if (elem?.detail?.opacity !== undefined && elem?.detail?.opacity >= 0) { | ||
ctx.globalAlpha = elem.detail.opacity; | ||
} else { | ||
ctx.globalAlpha = 1; | ||
} | ||
|
||
// draw border | ||
if (typeof borderWidth === 'number' && borderWidth > 0) { | ||
const ba = borderWidth / 2 + a; | ||
const bb = borderWidth / 2 + b; | ||
ctx.beginPath(); | ||
ctx.strokeStyle = borderColor; | ||
ctx.lineWidth = borderWidth; | ||
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI); | ||
ctx.closePath(); | ||
ctx.stroke(); | ||
} | ||
// draw border | ||
if (typeof borderWidth === 'number' && borderWidth > 0) { | ||
const ba = borderWidth / 2 + a; | ||
const bb = borderWidth / 2 + b; | ||
ctx.beginPath(); | ||
ctx.strokeStyle = borderColor; | ||
ctx.lineWidth = borderWidth; | ||
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI); | ||
ctx.closePath(); | ||
ctx.stroke(); | ||
} | ||
|
||
// draw content | ||
ctx.beginPath(); | ||
const fillStyle = createColorStyle(ctx, background, { | ||
viewElementSize: { x, y, w, h }, | ||
viewScaleInfo, | ||
opacity: ctx.globalAlpha | ||
// draw content | ||
ctx.beginPath(); | ||
const fillStyle = createColorStyle(ctx, background, { | ||
viewElementSize: { x, y, w, h }, | ||
viewScaleInfo, | ||
opacity: ctx.globalAlpha | ||
}); | ||
ctx.fillStyle = fillStyle; | ||
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
ctx.globalAlpha = 1; | ||
} | ||
}); | ||
ctx.fillStyle = fillStyle; | ||
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
ctx.globalAlpha = 1; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import type { ElementBaseDetail } from './element'; | ||
import type { ElementBaseDetail, ElementTextDetail } from './element'; | ||
|
||
export type DefaultElementDetailConfig = Required<Omit<ElementBaseDetail, 'clipPath' | 'background'>>; | ||
export type DefaultElementDetailConfig = Required<Omit<ElementBaseDetail, 'clipPath' | 'background'>> & | ||
Required<Pick<ElementTextDetail, 'color' | 'textAlign' | 'verticalAlign' | 'fontSize' | 'fontFamily' | 'fontWeight' | 'lineHeight'>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.