TLF - 通过多个容器和换行符流动文本
我正在使用 TLF 来布置字典条目。它工作得相当好,但我需要比通过在 FlowElements 上设置样式属性所能实现的更精细的布局控制,主要用于独立于其父级的 SpanElements 上的水平间距和设置填充。
看起来最有希望的解决方案是将条目的各个元素分离到单独的容器中,并通过为每个新元素逐步添加新容器和 ContainerController 来让文本流经它们,并将大小设置为其内容边界,以便文本将流入每个新元素。容器。
这几乎可以工作,但是如果在应该进入不同容器的文本的两个部分之间插入额外的换行符,则文本只会正确地流入下一个容器。如果没有换行符,容器的大小会正确,但不会显示任何文本。
在这些示例中,我向容器精灵添加了边框,以便您可以看到它们的绘制位置。除了换行符之外,文本完全相同。音节字段是 ParagraphElement 内的 SpanElement。发音标签和文本是另一个 ParagraphElement 内的单独 SpanElement。
没有换行符:
在 'rab-bit' 和 'Sounds Like:' 之间有换行符:
在 'rae biht' 之后换行(提前换行无效):
如您所见,除非在文本后添加换行符,否则不会显示发音,但对齐方式随即关闭。似乎没有任何换行符组合可以正确对齐它们。
有什么想法吗?这些错误是 TLF 中的吗?我应该尝试不同的方法吗?我真的很希望将所有文本作为一个单元进行选择,并且我喜欢 TLF 提供的更好的渲染和控制,但我还需要布局灵活性。我想我可以用换行符和定位偏移将类似的东西组合在一起,但它肯定不会很漂亮(或可维护)。感谢您的阅读。
I'm using TLF to lay out a dictionary entry. It's working fairly well, but I need finer grained control of layout than I'm able to achieve through setting style properties on FlowElements, primarily for horizontal spacing and setting padding on SpanElements independently of their parents.
The solution that seems most promising is separating the various elements of the entry into separate containers and flowing the text through them by progressively adding new containers and ContainerControllers for each new element with size set to their content bounds so that the text will flow into each new container.
This ALMOST works, but the text will only flow correctly into the next container if an extra line break is inserted between the two sections of text that should go to different containers. Without the line break, the containers are sized correctly, but no text displays.
In these examples I've added borders to the container sprites so you can see where they're being drawn. Aside from the line break, the text is exactly the same. The syllable field is a SpanElement inside a ParagraphElement. The pronunciation label and text are separate SpanElements inside another ParagraphElement.
Without line break:
With line break between 'rab-bit' and 'Sounds Like:':
With line break AFTER 'rae biht' (line break beforehand has no effect):
As you can see, the pronunciation doesn't show unless a line break is added after the text, but the alignment is then off. No combination of line breaks seems to align them correctly.
Any ideas? Are these bugs in TLF? Should I try a different method? I would really like to have all the text selectable as one unit, and I love the better rendering and control that TLF offers, but I also need the layout flexibility. I suppose it's possible that I could hack something together like this with line breaks and positioning offsets, but it certainly wouldn't be pretty (or maintainable). Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不久前为 Adobe Cookbooks 写了一个食谱,可能会对您有所帮助。基本上,我发现完全放弃使用 span 和 paragraph 元素而主要关注容器控制器要容易得多。希望它有帮助:
为纯文本资源生成格式化的 TextFlow 布局
更新
容器,您可能可以使用行尾分隔符来确定目标字符串,以及它的字符串长度、字体大小、填充等,您可以找到容器所需的大小并更改容器的大小通过调用相应的容器:
这是我写的另一个食谱,它自动更改文本流的字体大小以适合其容器: 自动化 TextFlow 容器的字体大小,
但您可以更改容器大小以适合您的文本,而不是像我所做的那样更改字体大小。
我希望这有帮助。
i wrote a recipe for Adobe Cookbooks a while back that might help you with this. basically, i found it much much easier to completely forgo using the span and paragraph elements in favor of focusing primarily on container controllers. hope it helps:
Generating a formatted TextFlow Layout for plain text assets
Update
for dynamic containers, you could probably use an end of line delimiter to determine your target string, along with it's string length, font size, padding, etc., you could find the required size for your container and change the size of your container accordingly by calling:
here is another recipe i wrote which automatically changes the font size of a text flow to fit inside its container: Automating font size for TextFlow containers
but instead of changing the font size as i have done, you could change the container size to fit your text.
i hope this helps.