Skip to content

Commit

Permalink
update: 添加根据字体属性自动加框功能
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin2li committed Jul 23, 2023
1 parent fd972a3 commit 97045c3
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 149 deletions.
31 changes: 29 additions & 2 deletions anki.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (a *App) CreateCardByRectAnnots(
a_mask_color string,
dpi int,
tags []string,
imageMode bool,
pages string) error {
logger.Printf("inFile: %s, outFile: %s, address: %s, parentDeck: %s, mode: %v, createSubDeck: %v, level: %d, q_mask_color: %s, a_mask_color: %s, dpi: %d, tags: %v, pages: %s\n", inFile, outFile, address, parentDeck, mode, createSubDeck, level, q_mask_color, a_mask_color, dpi, tags, pages)
args := []string{"anki"}
Expand All @@ -79,8 +80,34 @@ func (a *App) CreateCardByRectAnnots(
args = append(args, "--q-mask-color", q_mask_color)
args = append(args, "--a-mask-color", a_mask_color)
args = append(args, "--dpi", fmt.Sprintf("%d", dpi))
args = append(args, "--tags")
args = append(args, tags...)
if len(tags) > 0 {
args = append(args, "--tags")
args = append(args, tags...)
}
if imageMode {
args = append(args, "--image-mode")
}
if pages != "" {
args = append(args, "--page_range", pages)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
args = append(args, inFile)
logger.Println(args)
return a.cmdRunner(args, "pdf")
}

func (a *App) CreateCardByFontStyle(
inFile string,
outFile string,
matches []string,
pages string) error {
logger.Printf("inFile: %s, outFile: %s, matches: %v, pages: %s\n", inFile, outFile, matches, pages)
args := []string{"anki"}
args = append(args, "--type", "font_style")
args = append(args, "--matches")
args = append(args, matches...)
if pages != "" {
args = append(args, "--page_range", pages)
}
Expand Down
8 changes: 8 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func (a *App) PDFConversion(
sortDirection string,
srcType string,
dstType string,
paperSize string,
orientation string,
pages string) error {
logger.Printf("inFileList: %v, outFile: %s, dpi: %d, isMerge: %v, sortMethod: %s, sortDirection: %s, srcType: %s, dstType: %s, pages: %s\n", inFileList, outFile, dpi, isMerge, sortMethod, sortDirection, srcType, dstType, pages)
args := []string{"convert", "--source-type", srcType, "--target-type", dstType}
Expand All @@ -36,6 +38,12 @@ func (a *App) PDFConversion(
if sortDirection != "" {
args = append(args, "--sort-direction", sortDirection)
}
if paperSize != "" {
args = append(args, "--paper-size", paperSize)
}
if orientation != "" {
args = append(args, "--orientation", orientation)
}
if outFile != "" {
args = append(args, "-o", outFile)
}
Expand Down
291 changes: 184 additions & 107 deletions frontend/src/components/Forms/AnkiForm.vue

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions frontend/src/components/Forms/ConvertForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,61 @@
</a-form-item>
</div>
<div v-else-if="store.type === 'png2pdf' || store.type === 'svg2pdf'">
<a-form-item label="纸张大小">
<a-select v-model:value="store.paper_size" style="width: 200px">
<a-select-option value="same">与图片相同</a-select-option>
<a-select-option value="a0">A0</a-select-option>
<a-select-option value="a1">A1</a-select-option>
<a-select-option value="a2">A2</a-select-option>
<a-select-option value="a3">A3</a-select-option>
<a-select-option value="a4">A4</a-select-option>
<a-select-option value="a5">A5</a-select-option>
<a-select-option value="a6">A6</a-select-option>
<a-select-option value="a7">A7</a-select-option>
<a-select-option value="a8">A8</a-select-option>
<a-select-option value="a9">A9</a-select-option>
<a-select-option value="a10">A10</a-select-option>
<a-select-option value="b0">B0</a-select-option>
<a-select-option value="b1">B1</a-select-option>
<a-select-option value="b2">B2</a-select-option>
<a-select-option value="b3">B3</a-select-option>
<a-select-option value="b4">B4</a-select-option>
<a-select-option value="b5">B5</a-select-option>
<a-select-option value="b6">B6</a-select-option>
<a-select-option value="b7">B7</a-select-option>
<a-select-option value="b8">B8</a-select-option>
<a-select-option value="b9">B9</a-select-option>
<a-select-option value="b10">B10</a-select-option>
<a-select-option value="c0">C0</a-select-option>
<a-select-option value="c1">C1</a-select-option>
<a-select-option value="c2">C2</a-select-option>
<a-select-option value="c3">C3</a-select-option>
<a-select-option value="c4">C4</a-select-option>
<a-select-option value="c5">C5</a-select-option>
<a-select-option value="c6">C6</a-select-option>
<a-select-option value="c7">C7</a-select-option>
<a-select-option value="c8">C8</a-select-option>
<a-select-option value="c9">C9</a-select-option>
<a-select-option value="c10">C10</a-select-option>
<a-select-option value="card-4x6">card-4x6</a-select-option>
<a-select-option value="card-5x7">card-5x7</a-select-option>
<a-select-option value="commercial">commercial</a-select-option>
<a-select-option value="executive">executive</a-select-option>
<a-select-option value="invoice">invoice</a-select-option>
<a-select-option value="ledger">ledger</a-select-option>
<a-select-option value="legal">legal</a-select-option>
<a-select-option value="legal-13">legal-13</a-select-option>
<a-select-option value="letter">letter</a-select-option>
<a-select-option value="monarch">monarch</a-select-option>
<a-select-option value="tabloid-extra">tabloid-extra</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="纸张方向">
<a-radio-group v-model:value="store.orientation">
<a-radio value="portrait">纵向</a-radio>
<a-radio value="landscape">横向</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item name="is_merge" label="是否合并">
<a-checkbox v-model:checked="store.is_merge"></a-checkbox>
</a-form-item>
Expand Down Expand Up @@ -366,6 +421,8 @@ export default defineComponent({
store.sort_direction,
"pdf",
"png",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand All @@ -380,6 +437,8 @@ export default defineComponent({
store.sort_direction,
"pdf",
"svg",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand All @@ -401,6 +460,8 @@ export default defineComponent({
store.sort_direction,
"pdf",
"image-pdf",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand All @@ -419,6 +480,8 @@ export default defineComponent({
store.sort_direction,
"png",
"pdf",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand All @@ -437,6 +500,8 @@ export default defineComponent({
store.sort_direction,
"svg",
"pdf",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand All @@ -451,6 +516,8 @@ export default defineComponent({
store.sort_direction,
"epub",
"pdf",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand All @@ -465,6 +532,8 @@ export default defineComponent({
store.sort_direction,
"mobi",
"pdf",
store.paper_size,
store.orientation,
store.page,
])
break;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Forms/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@
</div>
</a-col>
<a-col>
<div class="mycard" @click="switchMenu('anki', '')">
<div class="mycard" @click="switchMenu('anki', 'annot')">
<div style="margin-top: 10px;">
<svg t="1690003829921" class="icon" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="5063" width="50" height="50">
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ interface ConvertState {
sort_method: string;
sort_direction: string;
input_list: string[];
paper_size: string;
orientation: string;
}
interface CompressState {
input: string;
Expand Down Expand Up @@ -330,6 +332,9 @@ interface AnkiState {
a_mask_color: string;
dpi: number,
tags: string[];
card_size: string;
is_image: false;
matches: string[];
}


Expand Down
8 changes: 7 additions & 1 deletion frontend/src/store/anki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const useAnkiState = defineStore("AnkiState", {
state: (): AnkiState => ({
input: "",
output: "",
op: "font",
op: "annot",
page: "",
address: "http://localhost:8765",
is_create_sub_deck: true,
Expand All @@ -16,6 +16,9 @@ export const useAnkiState = defineStore("AnkiState", {
a_mask_color: "#ffeba2",
dpi: 300,
tags: [],
card_size: "1",
is_image: false,
matches: ['same_font', 'same_size', 'same_color'],
}),
getters: {

Expand All @@ -36,6 +39,9 @@ export const useAnkiState = defineStore("AnkiState", {
a_mask_color: "#ffeba2",
dpi: 300,
tags: [],
card_size: "1",
is_image: false,
matches: ['same_font', 'same_size', 'same_color'],
})
},
}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/store/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const useConvertState = defineStore("ConvertState", {
is_merge: false,
sort_method: 'name',
sort_direction: 'asc',
input_list: []
input_list: [],
paper_size: "a4",
orientation: "portrait",
}),
getters: {

Expand All @@ -27,7 +29,9 @@ export const useConvertState = defineStore("ConvertState", {
is_merge: false,
sort_method: 'name',
sort_direction: 'asc',
input_list: []
input_list: [],
paper_size: "a4",
orientation: "portrait",
})
},
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function CompressPDF(arg1:string,arg2:string):Promise<void>;

export function ConvertPDF2Docx(arg1:string,arg2:string):Promise<void>;

export function CreateCardByRectAnnots(arg1:string,arg2:string,arg3:string,arg4:string,arg5:Array<string>,arg6:boolean,arg7:number,arg8:string,arg9:string,arg10:number,arg11:Array<string>,arg12:string):Promise<void>;
export function CreateCardByFontStyle(arg1:string,arg2:string,arg3:Array<string>,arg4:string):Promise<void>;

export function CreateCardByRectAnnots(arg1:string,arg2:string,arg3:string,arg4:string,arg5:Array<string>,arg6:boolean,arg7:number,arg8:string,arg9:string,arg10:number,arg11:Array<string>,arg12:boolean,arg13:string):Promise<void>;

export function CropPDFByBBOX(arg1:string,arg2:string,arg3:Array<number>,arg4:string,arg5:boolean,arg6:string):Promise<void>;

Expand Down Expand Up @@ -82,7 +84,7 @@ export function OCRPDFBookmark(arg1:string,arg2:string,arg3:string,arg4:string,a

export function OpenUrl(arg1:string):Promise<void>;

export function PDFConversion(arg1:Array<string>,arg2:string,arg3:number,arg4:boolean,arg5:string,arg6:string,arg7:string,arg8:string,arg9:string):Promise<void>;
export function PDFConversion(arg1:Array<string>,arg2:string,arg3:number,arg4:boolean,arg5:string,arg6:string,arg7:string,arg8:string,arg9:string,arg10:string,arg11:string):Promise<void>;

export function PandocConvert(arg1:string,arg2:string,arg3:string):Promise<void>;

Expand Down
12 changes: 8 additions & 4 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ export function ConvertPDF2Docx(arg1, arg2) {
return window['go']['main']['App']['ConvertPDF2Docx'](arg1, arg2);
}

export function CreateCardByRectAnnots(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) {
return window['go']['main']['App']['CreateCardByRectAnnots'](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
export function CreateCardByFontStyle(arg1, arg2, arg3, arg4) {
return window['go']['main']['App']['CreateCardByFontStyle'](arg1, arg2, arg3, arg4);
}

export function CreateCardByRectAnnots(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) {
return window['go']['main']['App']['CreateCardByRectAnnots'](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13);
}

export function CropPDFByBBOX(arg1, arg2, arg3, arg4, arg5, arg6) {
Expand Down Expand Up @@ -162,8 +166,8 @@ export function OpenUrl(arg1) {
return window['go']['main']['App']['OpenUrl'](arg1);
}

export function PDFConversion(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
return window['go']['main']['App']['PDFConversion'](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
export function PDFConversion(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) {
return window['go']['main']['App']['PDFConversion'](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
}

export function PandocConvert(arg1, arg2, arg3) {
Expand Down
Loading

0 comments on commit 97045c3

Please sign in to comment.