My copybook generator is open source!

xxy-copybook

introduce

When the child first started primary school, he wanted to get a copybook generator for the child, so that the child could practice more calligraphy. Because his father's writing was not good, he wanted to make the child's writing look more beautiful. For various reasons, the child was only in grade 4. I finished writing the copybook generator, I hope it is too late.
This is the core class library generated by copybooks. Now it is open sourced. I hope it can also help some friends who think like me.
My B station address: space.bilibili.com/1159595523
Nuggets address: juejin.cn/user/350569…

The main function

  • Supports defining the style of the copybook table. A variety of styles such as field characters, horizontal lines and borders can be customized and used together.
  • Support extended custom copybook cell style.
  • Pinyin copybooks are supported.
  • Customize the font used.
  • When there are too many words, it can automatically generate multi-page copybooks by paging.
  • A variety of usage styles can be used in one line or one line with multiple characters.

Software Architecture

  • Copybook cells are designed using the decorator pattern. To implement your own line segment style, you need to implement AbstractCellDecorator, and to implement text style, you need to implement AbstractCellTextDecorator. In cell.line is the implemented line segment decoration, and cell.text is the implemented text decoration.

  • The generation of copybooks uses the builder mode. CopybookDirector is the builder's director. To implement your own template, you need to implement AbstractCopybookBuilder.

  • Decorator UML Map for Core Styles1657432805444-ebb79f40-a413-4f7f-bc1d-8e71e13287a3.png

  • UML map of all classes1657432965905-df5b05c8-74d1-425b-92c3-82d58afe049a.png

Instructions for use

You can put your favorite fonts in the resources/fonts folder. Due to copyright issues, I can't provide fonts here, so you can collect them yourself.
Friends who hope to use it as soon as possible can take a look at these two classes:

  • CopybookTemplate is used to set the style of the copybook, including the background color of the copybook, the default border, etc.
  • CopybookData is used to set the copybook data, where the text to be displayed on the copybook, pinyin, and the content of the head and tail of the copybook are placed. A basic copybook generation code:
//设置显示的文字
String text = "屈渊孟甫韩愈禹锡仲龚";
//字体名字
String fontName = "嗡阿吽-田英章钢笔楷书简";

CopybookTemplate.CopybookTemplateBuilder copybookTemplateBuilder = CopybookTemplate.builder()
        .emptyCellNum(2)
        .textLineStroke(StrokeForCell.LINE)
        //单元格使用一个边框+田字格样式。
        .textCellLineStyle(CollUtil.toList(LineStyle.BORDER, LineStyle.TIAN));
//给边框格一个加粗的边线
copybookTemplateBuilder.textLineStrokeMap(MapUtil
        .builder(LineStyle.BORDER.getValue(), StrokeForCell.LINE_BOLD)
        .build());
Font font = new Font(fontName, Font.PLAIN, 140);
copybookTemplateBuilder.font(font);
//设置模板数据
CopybookTemplate copybookTemplate = copybookTemplateBuilder.pagePadding(new Integer[]{10,10,10,200}).build();
CopybookData copybookData = CopybookData.builder()
        .author("Radium")
        .wordList(CollUtil.toList(text.split("")))
        .build();

BaseCopybook baseCopybook = new BaseCopybook(copybookTemplate, copybookData);
CopybookDirector director = new CopybookDirector(baseCopybook);
try {
    Copybook construct = director.buildCopybook();
    BufferedImage bufferedImage = construct.exportFirstImage();
    //输出图像
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", output);
    FileUtil.writeBytes(output.toByteArray(),
            new File(outputPath+"construct.png"));
} catch (Exception e) {
    e.printStackTrace();
}

The overall usage process is as follows:

  1. Set template styles via CopybookTemplate.
  2. Set template data via CopybookData.
  3. Use the template's BaseCopybook to generate copybooks. For more usage methods, see AppTest in test.

Participate and contribute

There are still many imperfections in the works of personal leisure time. You are welcome to submit code.

  1. Fork this repository
  2. New Feat_xxx branch
  3. Submit code
  4. New Pull Request

Example

  • basic copybookconstruct.png
  • Pinyin copybookconstructPinyin0.png
  • Set the header and footer of the copybookconstructHeaderAndFooter0.png
  • Automatic multi-page copybook
    • The first pageconstructMore0.png
    • The second pageconstructMore1.png

Guess you like

Origin juejin.im/post/7118635049779462157