2

我有一个自定义方法,它接受一个字符串和一个块,并且应该在带有圆角边框的矩形内显示块传递的任何调用。当内容足够小以适合剩余页面时,这非常有效,但是当它不是仅在第二页上显示的边框时,它们比应有的长并且标题似乎消失了

这是它应该看起来的样子

好的

这是跨越两页的大量内容(在本例中为文本)的外观:

第 1 页:

不好 - 第 1 页

第2页:

不好 - 第 2 页

def get_size_of_text str, opts
      ret = [0, 0]
      font(opts[:fontName], style: opts[:fontStyle], size: opts[:fontSize]) do
          ret = [
              height_of_typeset_text(str),
              rendered_width_of_string(str)
          ]
      end
      ret
  end

def customBox title, &block
      title_height, title_width = get_size_of_text title, fontName: "M+ 1mn", fontStyle: :bold, fontSize: 20

      title_width += 30
      title_height += 5

      stroke do
          fill_color '000000'
          fill_and_stroke_rounded_rectangle [(page_usable_width - title_width) * 0.5, cursor + 5], title_width, title_height, 10
          fill_color '000000'
      end

      box = bounding_box [0, cursor], width: page_usable_width do
          move_down title_height
          bounding_box [10, cursor], width: page_usable_width - 20 do
              block.call
          end
      end

      stroke do
          stroke_color '000000'
          line_width 2.5
          stroke_rounded_rectangle [0, cursor + box.update_height - 10], page_usable_width, box.update_height - 20, 10
      end

      move_up box.update_height

      font("M+ 1mn", :style => :bold, size: 20, align: :center) do
          stroke_color "ffffff"
          fill_color "ffffff"
          text title, align: :center
      end

      move_down box.update_height - 20
  end
4

0 回答 0