Prawn(Ruby) - 如何使用:inline_format <color rgb =“”> </color>,但仍保留文本笔划?

时间:2015-05-24 07:52:49

标签: ruby prawn

我知道,看看Prawn手册,你可以将内联文字画成“描边”,就像这样(来自手册):

fill_color "00ff00"
stroke_color "0000ff"

font_size(40) do
  # normal rendering mode: fill
  text "This text is filled with green."
  move_down 20

  # inline rendering mode: stroke
  text "This text is stroked with blue", :mode => :stroke
  move_down 20

  # block rendering mode: fill and stroke
  text_rendering_mode(:fill_stroke) do
    text "This text is filled with green and stroked with blue"
  end

我也知道您可以控制内联格式,如下所示:

"aaaaaaaaaaaaaaa <color rgb="xxxxxx">UP</color> aaaaaaaa"

但是现在“UP”没有按照应有的概括。

如何概述文本并使用inline_formatting?我可以吗?

以下是我尝试过的一个例子:

require 'prawn'

class SomeDoc < Prawn::Document
    def initialize
        super({:margin => [5,5], :page_size => 'A4'})
    end

    def draw_text
        the_text = "the word <color rgb='74B743'>DOWN</color> should be a different color and be outlined"

        text_rendering_mode(:fill_stroke) do
            stroke_color "000000"
            fill_color "FFFFFF"
            text(the_text, :inline_format => true)
        end
    end
end

test = SomeDoc.new
test.draw_text
test.render_file('test.pdf')

1 个答案:

答案 0 :(得分:0)

pdf.text_rendering_mode(:fill_stroke) do
  pdf.stroke_color "431CEF"
  pdf.text("Outlined Text")
end

而不是stroke_color,你必须这样做:

pdf.stroke_color