-
-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
113 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { DeepRequired } from '../../../interface/Common' | ||
import { IEditorOption } from '../../../interface/Editor' | ||
import { Draw } from '../Draw' | ||
import { Footer } from './Footer' | ||
import { Header } from './Header' | ||
|
||
export class PageBorder { | ||
private draw: Draw | ||
private header: Header | ||
private footer: Footer | ||
private options: DeepRequired<IEditorOption> | ||
|
||
constructor(draw: Draw) { | ||
this.draw = draw | ||
this.header = draw.getHeader() | ||
this.footer = draw.getFooter() | ||
this.options = draw.getOptions() | ||
} | ||
|
||
public render(ctx: CanvasRenderingContext2D) { | ||
const { | ||
scale, | ||
pageBorder: { color, lineWidth, padding } | ||
} = this.options | ||
ctx.save() | ||
ctx.translate(0.5, 0.5) | ||
ctx.strokeStyle = color | ||
ctx.lineWidth = lineWidth * scale | ||
const margins = this.draw.getMargins() | ||
// x:左边距 - 左距离正文距离 | ||
const x = margins[3] - padding[3] * scale | ||
// y:页眉上边距 + 页眉高度 - 上距离正文距离 | ||
const y = margins[0] + this.header.getExtraHeight() - padding[0] * scale | ||
// width:页面宽度 + 左右距离正文距离 | ||
const width = this.draw.getInnerWidth() + (padding[1] + padding[3]) * scale | ||
// height:页面高度 - 正文起始位置 - 页脚高度 - 下边距 - 下距离正文距离 | ||
const height = | ||
this.draw.getHeight() - | ||
y - | ||
this.footer.getExtraHeight() - | ||
margins[2] + | ||
padding[2] * scale | ||
ctx.rect(x, y, width, height) | ||
ctx.stroke() | ||
ctx.restore() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IPageBorderOption } from '../../interface/PageBorder' | ||
|
||
export const defaultPageBorderOption: Readonly<Required<IPageBorderOption>> = { | ||
color: '#000000', | ||
lineWidth: 1, | ||
padding: [0, 5, 0, 5], | ||
disabled: true | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IPadding } from './Common' | ||
|
||
export interface IPageBorderOption { | ||
color?: string | ||
lineWidth?: number | ||
padding?: IPadding | ||
disabled?: boolean | ||
} |
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