[Gambas-user] R: Fitting RichtText into several limited areas
Rolf-Werner Eilert
eilert-sprachen at ...221...
Tue Dec 8 16:09:14 CET 2015
Thank you very much for this code. It shows me some tricks I wasn't
aware of, and I could understand how you would "measure" the point where
to cut the text to spread it on several boxes.
But there is one thing this code does not consider, and that is the way
tagged text is interpreted. As an example, you gave me this paragraph:
<h1>'if it stopped drawing at 70 mm</h1>
Paint.DrawRichText(sRtext, x1, y1, width, frameLength)
Paint.DrawRichText(RSTring.Mid(sRtext, RichTextLength(sRtext,
frameLength) + 1, x2, y2, W, frameLength)
Now, just try to delete the closing tag and set it at the end of the
paragraph. The second half of the paragraph lands in the next box, but
you will see that (of course) the text is continued in default style there.
When you use a file from a RichTextArea, there will be a complete
structure of XML, including header, spans, <html></html> tags etc. You
cannot simply cut in between - that would destroy it.
Instead, one solution might be to see it like an XML structure of data,
and interpret the strings of text only alongside the printed result like
you did. When you have to cut such a string, you will have to build up a
complete new XML structure with headers and leading tags, but beginning
with the formats for this string and with the new part-string.
In short:
<!DOCTYPE HTML PUBLIC blah blah...>
<HTML>
<HEAD>
blah
</HEAD>
<BODY>
This is a first paragraph <b>in bold</b> <h1>and very large</h1>
</BODY>
</HTML>
Now, if you cut before the "very large" string, you will have to make a
new text with
<!DOCTYPE HTML PUBLIC blah blah...>
<HTML>
<HEAD>
blah
</HEAD>
<BODY>
<h1>very large</h1>
</BODY>
</HTML>
to let this part appear the same way in the new box.
So if your algorithm says "a new box has to start in the middle of
string 'very large'", you will have to reconstruct all formats and tags
for this part of the text plus header etc. and cut it there and place
the rest into a new complete XML structure. Your code helps a lot here,
but it's unfortunately only half way.
Regards
Rolf
Am 05.12.2015 11:10, schrieb Fabien Bodard:
> re OOpps, I've just see i've forgotten to manage when one line not fit
> in the area.
>
> 2015-12-05 11:04 GMT+01:00 Fabien Bodard <gambas.fr at ...626...>:
>> Hoops an insidious bug .
>>
>> 2015-12-05 10:19 GMT+01:00 Fabien Bodard <gambas.fr at ...626...>:
>>> So this is my two cents. It's not optimized i should do better if i've
>>> time. I will use something like this in a near time for reportLabels.
>>>
>>> Regards
>>> --
>>> Fabien Bodard
>>>
>>> 2015-12-04 13:04 GMT+01:00 Rolf-Werner Eilert <eilert-sprachen at ...3549....>:
>>>> I don't think so, because it describes the wideth of a single line of
>>>> richtext.
>>>>
>>>> Paint.Richtext or Paint.DrawRichtext accept a Height for the textframe,
>>>> but it is practically unused. The function goes on drawing beyond this
>>>> point. This is where you would have to start helping.
>>>>
>>>> Let's see what would be necessary to do what I was looking for,
>>>> something pseudo code:
>>>>
>>>> frameLength = 70 'mm
>>>>
>>>> sRtext = File.Load("myrichtext")
>>>>
>>>> If Paint.RichTextHeight(sRtext) > frameLength Then
>>>>
>>>> 'if it stopped drawing at 70 mm
>>>> Paint.DrawRichText(sRtext, x1, y1, width, frameLength)
>>>> Paint.DrawRichText(RSTring.Mid(sRtext, RichTextLength(sRtext,
>>>> frameLength) + 1, x2, y2, W, frameLength)
>>>>
>>>> 'like it is now, not stopping, with special cutting function
>>>> Paint.DrawRichText(RString.Left(sRtext, RichTextLength(sRtext,
>>>> frameLength)), x1, y1, W, frameLength)
>>>> Paint.DrawRichText(RString.Mid(sRtext, RichTextLength(sRtext,
>>>> frameLength) + 1, x2, y2, W, frameLength)
>>>>
>>>> Else
>>>>
>>>> Paint.DrawRichText(sRtext, x1, y1, width, frameLength)
>>>>
>>>> Endif
>>>>
>>>>
>>>> So, this is just phantasy, but does it make it clearer? A class RString
>>>> would be needed, and a function that finds the position of the last
>>>> printable character in a RichText of given width. But I know, catenating
>>>> of these tagged strings would mean interpreting them, it's rather tricky...
>>>>
>>>> Regards
>>>> Rolf
>>>>
>>>>
>>>> Am 04.12.2015 12:05, schrieb Ru Vuott:
>>>>> Hello,
>>>>>
>>>>> ...could .Font.RichTextWidth() function help you ?
>>>>>
>>>>> vuott
>>>>>
>>>>>
>>>>>
>>>>> --------------------------------------------
>>>>> Ven 4/12/15, Rolf-Werner Eilert <eilert-sprachen at ...221...> ha scritto:
>>>>>
>>>>> Oggetto: [Gambas-user] Fitting RichtText into several limited areas
>>>>> A: "mailing list for gambas users" <gambas-user at ...720...net>
>>>>> Data: Venerdì 4 dicembre 2015, 10:01
>>>>>
>>>>> Can I somehow predict where a
>>>>> RichText will be too long for a box of
>>>>> text on a page, then cut it there, and let the rest flow
>>>>> into another box?
>>>>>
>>>>> You all know this from DTP programs: you have several text
>>>>> frames, and
>>>>> text is running on from one frame into the next if too
>>>>> long.
>>>>>
>>>>> I guess this isn't possible because there seems to be no
>>>>> intelligent
>>>>> helper function that can handle RichText strings like e. g.
>>>>> UTF-8
>>>>> strings are handled in contrary to ASCII strings. As far as
>>>>> I can see,
>>>>> RichText is simply a UTF-8 string containing a lot of XML
>>>>> tags. A
>>>>> special Left, Mid or Right function would have to
>>>>> reconstruct these tags
>>>>> for the other part of the string to keep the tags
>>>>> functionable.
>>>>>
>>>>> A workaround would be to extract the pure text and store the
>>>>> tagged
>>>>> values somewhere else until the text has been cut apart. But
>>>>> it would
>>>>> make the whole automatic in RichText senseless.
>>>>>
>>>>> But maybe I just didn't find this functionality?
>>>>>
>>>>> Regards
>>>>> Rolf
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> Go from Idea to Many App Stores Faster with Intel(R) XDK
>>>>> Give your users amazing mobile app experiences with Intel(R)
>>>>> XDK.
>>>>> Use one codebase in this all-in-one HTML5 development
>>>>> environment.
>>>>> Design, debug & build mobile apps & 2D/3D
>>>>> high-impact games for multiple OSs.
>>>>> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
>>>>> _______________________________________________
>>>>> Gambas-user mailing list
>>>>> Gambas-user at lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Go from Idea to Many App Stores Faster with Intel(R) XDK
>>>> Give your users amazing mobile app experiences with Intel(R) XDK.
>>>> Use one codebase in this all-in-one HTML5 development environment.
>>>> Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
>>>> _______________________________________________
>>>> Gambas-user mailing list
>>>> Gambas-user at lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>>
>>> --
>>> Fabien Bodard
>>
>>
>> --
>> Fabien Bodard
>
>
>
>
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
>
>
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
More information about the User
mailing list