答案 0 :(得分:3)
是的,有一种方法可以在Praw中创建领导者点效果。
如果你有:
> db.c20160712.updateOne( { "Attribute" : "good"}, {"Type" : "DVD", "Title" : "Matrix, The", "Released" : 1999, "Genre" : "Action"}, { upsert: true} )
2016-08-10T16:37:57.089-0400 E QUERY [thread1] Error: the update operation document must contain atomic operators :
DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:493:1
@(shell):1:1
space_for_dots = 1. - 2. - 3.
dots = (space_for_dots / 4) * '.'
要计算prawn中字符串的宽度,可以使用compute_width_of,它是字体类的一部分。
您添加的图片示例如下:
toc_entry = entry_string + dots + entry_page_number
答案 1 :(得分:0)
这有点晚了,但是这是我所做的使点仅与左侧文本正确对齐的操作。但是我认为修改左右文本会相当容易:
def build_dots(text, available_width, text_size)
dots_hash = {}
current_font = font.inspect.split('<')[1].split(':')[0].strip
text_width = font(current_font).compute_width_of(text, size: text_size)
dot_width = font(current_font).compute_width_of('.', size: text_size)
space_width = font(current_font).compute_width_of(' ', size: text_size)
space_for_dots = available_width - text_width - space_width * 2
dots = '.' * (space_for_dots / dot_width)
dots_width = font(current_font).compute_width_of(dots, size: text_size)
dots_start = available_width - dots_width - (space_width * 2)
dots_hash[:dots] = dots
dots_hash[:position] = dots_start
return dots_hash
end
dot_values = build_dots(officer.title,150,text_size)
p = 0
float {
text "#{officer.title}", size: text_size
}
indent(dot_values[:position]) do
float {
text dot_values[:dots], size: text_size
}
end
p += 150
indent(p,0) do
text "#{officer.name}", size: text_size
end