thinreports / thinreports-generator

A Ruby library for Thinreports
https://github.com/thinreports/thinreports
MIT License
297 stars 48 forks source link

How to make the texts of a text block align to a text? #100

Closed tan-wei closed 4 years ago

tan-wei commented 4 years ago

I find it hard to align a text block to a text. For example, a layout is created as following: 图片

{
  "version": "0.10.0",
  "items": [
    {
      "id": "",
      "type": "rect",
      "display": true,
      "description": "",
      "x": 20,
      "y": 150,
      "width": 187.5,
      "height": 20.5,
      "style": {
        "border-color": "#a5a5a5",
        "border-width": 0.5,
        "border-style": "solid",
        "fill-color": "none"
      },
      "border-radius": 0
    },
    {
      "id": "",
      "type": "rect",
      "display": true,
      "description": "",
      "x": 207.7,
      "y": 150,
      "width": 367.5,
      "height": 20.5,
      "style": {
        "border-color": "#a5a5a5",
        "border-width": 0.5,
        "border-style": "solid",
        "fill-color": "none"
      },
      "border-radius": 0
    },
    {
      "id": "",
      "type": "text",
      "display": true,
      "description": "",
      "x": 20,
      "y": 150,
      "width": 187.5,
      "height": 20.5,
      "style": {
        "font-family": [
          "Helvetica"
        ],
        "font-size": 18,
        "color": "#000000",
        "text-align": "center",
        "vertical-align": "middle",
        "line-height": "",
        "line-height-ratio": "",
        "letter-spacing": "",
        "font-style": []
      },
      "texts": [
        "Text"
      ]
    },
    {
      "id": "text_block",
      "type": "text-block",
      "display": true,
      "description": "",
      "x": 207.7,
      "y": 150,
      "width": 367.5,
      "height": 20.5,
      "style": {
        "font-family": [
          "Helvetica"
        ],
        "font-size": 18,
        "color": "#000000",
        "text-align": "left",
        "vertical-align": "top",
        "line-height": "",
        "line-height-ratio": "",
        "letter-spacing": "",
        "font-style": [],
        "overflow": "truncate",
        "word-wrap": "break-word"
      },
      "reference-id": "",
      "value": "",
      "multiple-line": false,
      "format": {
        "base": "",
        "type": ""
      }
    }
  ],
  "state": {
    "layout-guides": []
  },
  "title": "demo",
  "report": {
    "paper-type": "A4",
    "orientation": "portrait",
    "margin": [
      20,
      20,
      20,
      20
    ]
  }
}

We can see in the editor, the top location of "Text Block" is equal to the top location of "Text". However, the output PDF is: 图片

Is there an easy way to align them? I can't find an easy way in examples. estimate-ja provides a pretty result, but how?

Thanks very much!

tan-wei commented 4 years ago

Quite easy to get the result with the code:

require 'thinreports'

report = Thinreports::Report.new layout: 'align_test.tlf'

report.start_new_page do |page|
  page.item(:text_block).set("Text Box")
end

report.generate filename: 'align_test.pdf'

And the TLF file: align_test.zip

hidakatsuya commented 4 years ago

Sorry for late reply.

You will be able to solve you issue in the following ways:

image

The PDF output with a template with the above settings is as follows:

image

tan-wei commented 4 years ago

Thanks very much!