[Jlatexmath] Option for max. width vs exact width: Remaining Problem

classic Classic list List threaded Threaded
7 messages Options
Felix Natter Felix Natter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Jlatexmath] Option for max. width vs exact width: Remaining Problem

Happy new year Calixte and Sylvestre!
(ok, it's a bit late ;-)

In the "maximum width feature" I replaced this:

HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
  te.getTextwidth(), il), te.getTextwidth(), align);

with:

HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
  te.getTextwidth(), il), 0, align);

This works fine for ALIGN_LEFT, but not for ALIGN_CENTER and
ALIGN_RIGHT (1). Here is a sample piece of code (complete example attached):

    String latex = "\\text{hello world}";
                TeXFormula formula = new TeXFormula(latex);
                TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_TEXT)
                                .setSize(16)
                                .setWidth(TeXConstants.UNIT_PIXEL, 256f, TeXConstants.ALIGN_CENTER)
                                .setIsMaxWidth(true).setInterLineSpacing(TeXConstants.UNIT_PIXEL, 20f)
                                .build();

(the hello world is cut off, with setIsMaxWidth(false) the text is
correctly centered on 256px)

Also (2) "\text{hello world\\hello}" (with setIsMaxWIdth==false) results
in:
    [  hello world  ]
    [  hello        ]
and not:
    [  hello world  ]
    [     hello     ]

Now if we fix (1) by forcing align := LEFT if setIsMaxWidth==true,
what we lose is this case:
[hello world]
[   hello   ]
=> it would be rendered as:
[hello world]
[hello      ]
=> but that is already the current behavior (see (2) above).
=> so I suggest forcing align := LEFT if setIsMaxWidth==true
   in TeXIconBuilder until (2) is fixed/improved.
   What do you think?


BTW: Could you consider applying the patch from this mail too?
"[Jlatexmath] Patch: Make basic examples use builder interface"

Thanks and Best Regards!
--
Felix Natter

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;


public class ExampleSwing2 {
        public static void main(String[] args)
        {
        String latex = "\\text{hello world}";
                TeXFormula formula = new TeXFormula(latex);
                TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY)
                                .setSize(16)
                                .setWidth(TeXConstants.UNIT_PIXEL, 256f, TeXConstants.ALIGN_CENTER)
                                .setIsMaxWidth(true).setInterLineSpacing(TeXConstants.UNIT_PIXEL, 20f)
                                .build();
               
                JFrame frame = new JFrame();
                final JLabel label = new JLabel(icon);
                label.setMaximumSize(new Dimension(100,300));
                label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
                frame.getContentPane().add(label);

                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);
        }

}

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Sylvestre Ledru-4 Sylvestre Ledru-4
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Option for max. width vs exact width: Remaining Problem

On 13/01/2013 17:04, Felix Natter wrote:

> Happy new year Calixte and Sylvestre!
> (ok, it's a bit late ;-)
>
> In the "maximum width feature" I replaced this:
>
> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>   te.getTextwidth(), il), te.getTextwidth(), align);
>
> with:
>
> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>   te.getTextwidth(), il), 0, align);
Could you provide an actual patch or let us know in which files this
change should be made ?

[...]

>
> BTW: Could you consider applying the patch from this mail too?
> "[Jlatexmath] Patch: Make basic examples use builder interface"
For now, I added your example
http://forge.scilab.org/index.php/p/jlatexmath/source/commit/e848fd52c0f2c3f46b7ea9dcf262ec4b2a2c6c2f/

Thanks,
S

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Felix Natter Felix Natter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Option for max. width vs exact width: Remaining Problem

hello Sylvestre,

Sylvestre Ledru <[hidden email]> writes:

> On 13/01/2013 17:04, Felix Natter wrote:
>> Happy new year Calixte and Sylvestre!
>> (ok, it's a bit late ;-)
>>
>> In the "maximum width feature" I replaced this:
>>
>> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>>   te.getTextwidth(), il), te.getTextwidth(), align);
>>
>> with:
>>
>> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>>   te.getTextwidth(), il), 0, align);
> Could you provide an actual patch or let us know in which files this
> change should be made ?
>
> [...]

Yes sure, here it is (changes the TeXIconBuilder.setIsMaxWidth()
method):

--------------------------------------------
diff --git a/src/org/scilab/forge/jlatexmath/TeXFormula.java b/src/org/scilab/forge/jlatexmath/TeXFormula.java
index b2ee428..6198ac8 100644
--- a/src/org/scilab/forge/jlatexmath/TeXFormula.java
+++ b/src/org/scilab/forge/jlatexmath/TeXFormula.java
@@ -698,6 +698,25 @@ public class TeXFormula {
             {
                 throw new IllegalStateException("Cannot set 'isMaxWidth' without having specified a width!");
             }
+            if (isMaxWidth)
+            {
+             // NOTE: Currently isMaxWidth==true does not work with ALIGN_CENTER or ALIGN_RIGHT (see HorizontalBox ctor)
+             // The case (1) we don't support by setting align := ALIGN_LEFT here is this:
+             //  \text{hello world\\hello} with align=ALIGN_CENTER (but forced to ALIGN_LEFT) and isMaxWidth==true results in:
+             // [hello world]
+             // [hello      ]
+             // and NOT:
+             // [hello world]
+             // [   hello   ]
+             // However, this case (2) is currently not supported anyway (ALIGN_CENTER with isMaxWidth==false):
+             // [  hello world  ]
+             // [  hello        ]
+             // and NOT:
+             // [  hello world  ]
+             // [     hello     ]
+             // => until (2) is solved, we stick with the hack to set align := ALIGN_LEFT!
+             this.align = TeXConstants.ALIGN_LEFT;
+            }
             this.isMaxWidth = isMaxWidth;
             return this;
         }
--------------------------------------------

This fixes problems with ALIGN_CENTER/ALIGN_RIGHT in combination with
isMaxWidth==true.
The basic problem with (2) is that in HorizontalBox-ctor, the StrutBoxes
are used globally for all lines and are calculated on the maximum width.
That's why we cannot currently support:
[  hello world  ]
[     hello     ]
but only:
[  hello world  ]
[  hello        ]

I hope that is all correct :-)
I can also supply an example for (2).

>>
>> BTW: Could you consider applying the patch from this mail too?
>> "[Jlatexmath] Patch: Make basic examples use builder interface"
> For now, I added your example
>
>> http://forge.scilab.org/index.php/p/jlatexmath/source/commit/e848fd52c0f2c3f46b7ea9dcf262ec4b2a2c6c2f/

OK.

Is there a reason why you don't like adding the builder interface to the
examples? IMHO it's more extensible and easier to read.

Thank you!
--
Felix Natter
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Felix Natter Felix Natter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Option for max. width vs exact width: Remaining Problem

Felix Natter <[hidden email]> writes:
> Yes sure, here it is (changes the TeXIconBuilder.setIsMaxWidth()
> method):

Sorry, I now attached the patch, should be easier to apply ;-)

Thanks,
--
Felix Natter

diff --git a/src/org/scilab/forge/jlatexmath/TeXFormula.java b/src/org/scilab/forge/jlatexmath/TeXFormula.java
index b2ee428..6198ac8 100644
--- a/src/org/scilab/forge/jlatexmath/TeXFormula.java
+++ b/src/org/scilab/forge/jlatexmath/TeXFormula.java
@@ -698,6 +698,25 @@ public class TeXFormula {
             {
                 throw new IllegalStateException("Cannot set 'isMaxWidth' without having specified a width!");
             }
+            if (isMaxWidth)
+            {
+             // NOTE: Currently isMaxWidth==true does not work with ALIGN_CENTER or ALIGN_RIGHT (see HorizontalBox ctor)
+             // The case (1) we don't support by setting align := ALIGN_LEFT here is this:
+             //  \text{hello world\\hello} with align=ALIGN_CENTER (but forced to ALIGN_LEFT) and isMaxWidth==true results in:
+             // [hello world]
+             // [hello      ]
+             // and NOT:
+             // [hello world]
+             // [   hello   ]
+             // However, this case (2) is currently not supported anyway (ALIGN_CENTER with isMaxWidth==false):
+             // [  hello world  ]
+             // [  hello        ]
+             // and NOT:
+             // [  hello world  ]
+             // [     hello     ]
+             // => until (2) is solved, we stick with the hack to set align := ALIGN_LEFT!
+             this.align = TeXConstants.ALIGN_LEFT;
+            }
             this.isMaxWidth = isMaxWidth;
             return this;
         }

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Sylvestre Ledru-4 Sylvestre Ledru-4
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Option for max. width vs exact width: Remaining Problem

In reply to this post by Felix Natter
On 18/01/2013 11:02, Felix Natter wrote:

> hello Sylvestre,
>
> Sylvestre Ledru <[hidden email]> writes:
>> On 13/01/2013 17:04, Felix Natter wrote:
>>> Happy new year Calixte and Sylvestre!
>>> (ok, it's a bit late ;-)
>>>
>>> In the "maximum width feature" I replaced this:
>>>
>>> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>>>   te.getTextwidth(), il), te.getTextwidth(), align);
>>>
>>> with:
>>>
>>> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>>>   te.getTextwidth(), il), 0, align);
>> Could you provide an actual patch or let us know in which files this
>> change should be made ?
>>
>> [...]
>
> Yes sure, here it is (changes the TeXIconBuilder.setIsMaxWidth()
> method):
>
> --------------------------------------------
> diff --git a/src/org/scilab/forge/jlatexmath/TeXFormula.java b/src/org/scilab/forge/jlatexmath/TeXFormula.java
> index b2ee428..6198ac8 100644
> --- a/src/org/scilab/forge/jlatexmath/TeXFormula.java
> +++ b/src/org/scilab/forge/jlatexmath/TeXFormula.java
> @@ -698,6 +698,25 @@ public class TeXFormula {
>              {
>                  throw new IllegalStateException("Cannot set 'isMaxWidth' without having specified a width!");
>              }
> +            if (isMaxWidth)
> +            {
> +             // NOTE: Currently isMaxWidth==true does not work with ALIGN_CENTER or ALIGN_RIGHT (see HorizontalBox ctor)
> +             // The case (1) we don't support by setting align := ALIGN_LEFT here is this:
> +             //  \text{hello world\\hello} with align=ALIGN_CENTER (but forced to ALIGN_LEFT) and isMaxWidth==true results in:
> +             // [hello world]
> +             // [hello      ]
> +             // and NOT:
> +             // [hello world]
> +             // [   hello   ]
> +             // However, this case (2) is currently not supported anyway (ALIGN_CENTER with isMaxWidth==false):
> +             // [  hello world  ]
> +             // [  hello        ]
> +             // and NOT:
> +             // [  hello world  ]
> +             // [     hello     ]
> +             // => until (2) is solved, we stick with the hack to set align := ALIGN_LEFT!
> +             this.align = TeXConstants.ALIGN_LEFT;
> +            }
>              this.isMaxWidth = isMaxWidth;
>              return this;
>          }
> --------------------------------------------
>
> This fixes problems with ALIGN_CENTER/ALIGN_RIGHT in combination with
> isMaxWidth==true.
> The basic problem with (2) is that in HorizontalBox-ctor, the StrutBoxes
> are used globally for all lines and are calculated on the maximum width.
> That's why we cannot currently support:
> [  hello world  ]
> [     hello     ]
> but only:
> [  hello world  ]
> [  hello        ]
>
> I hope that is all correct :-)
Looks like. I applied the patch.
http://forge.scilab.org/index.php/p/jlatexmath/source/commit/84252b89dc9d877395e7bc80c621808748509a8f/

> I can also supply an example for (2).
>
>>>
>>> BTW: Could you consider applying the patch from this mail too?
>>> "[Jlatexmath] Patch: Make basic examples use builder interface"
>> For now, I added your example
>>
>>> http://forge.scilab.org/index.php/p/jlatexmath/source/commit/e848fd52c0f2c3f46b7ea9dcf262ec4b2a2c6c2f/
>
> OK.
>
> Is there a reason why you don't like adding the builder interface to the
> examples? IMHO it's more extensible and easier to read.
?
ant example
builds the example

Sylvestre



_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Felix Natter Felix Natter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Option for max. width vs exact width: Remaining Problem

Sylvestre Ledru <[hidden email]> writes:

> On 18/01/2013 11:02, Felix Natter wrote:
>> hello Sylvestre,
>>
>> Sylvestre Ledru <[hidden email]> writes:
>>> On 13/01/2013 17:04, Felix Natter wrote:
>>>> Happy new year Calixte and Sylvestre!
>>>> (ok, it's a bit late ;-)
>>>>
>>>> In the "maximum width feature" I replaced this:
>>>>
>>>> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>>>>   te.getTextwidth(), il), te.getTextwidth(), align);
>>>>
>>>> with:
>>>>
>>>> HorizontalBox hb = new HorizontalBox(BreakFormula.split(box,
>>>>   te.getTextwidth(), il), 0, align);
>>> Could you provide an actual patch or let us know in which files this
>>> change should be made ?
>>>
>>> [...]
>>
>> Yes sure, here it is (changes the TeXIconBuilder.setIsMaxWidth()
>> method):
>>
>> --------------------------------------------
>> diff --git a/src/org/scilab/forge/jlatexmath/TeXFormula.java b/src/org/scilab/forge/jlatexmath/TeXFormula.java
>> index b2ee428..6198ac8 100644
>> --- a/src/org/scilab/forge/jlatexmath/TeXFormula.java
>> +++ b/src/org/scilab/forge/jlatexmath/TeXFormula.java
>> @@ -698,6 +698,25 @@ public class TeXFormula {
>>              {
>>                  throw new IllegalStateException("Cannot set 'isMaxWidth' without having specified a width!");
>>              }
>> +            if (isMaxWidth)
>> +            {
>> +             // NOTE: Currently isMaxWidth==true does not work with ALIGN_CENTER or ALIGN_RIGHT (see HorizontalBox ctor)
>> +             // The case (1) we don't support by setting align := ALIGN_LEFT here is this:
>> +             //  \text{hello world\\hello} with align=ALIGN_CENTER (but forced to ALIGN_LEFT) and isMaxWidth==true results in:
>> +             // [hello world]
>> +             // [hello      ]
>> +             // and NOT:
>> +             // [hello world]
>> +             // [   hello   ]
>> +             // However, this case (2) is currently not supported anyway (ALIGN_CENTER with isMaxWidth==false):
>> +             // [  hello world  ]
>> +             // [  hello        ]
>> +             // and NOT:
>> +             // [  hello world  ]
>> +             // [     hello     ]
>> +             // => until (2) is solved, we stick with the hack to set align := ALIGN_LEFT!
>> +             this.align = TeXConstants.ALIGN_LEFT;
>> +            }
>>              this.isMaxWidth = isMaxWidth;
>>              return this;
>>          }
>> --------------------------------------------
>>
>> This fixes problems with ALIGN_CENTER/ALIGN_RIGHT in combination with
>> isMaxWidth==true.
>> The basic problem with (2) is that in HorizontalBox-ctor, the StrutBoxes
>> are used globally for all lines and are calculated on the maximum width.
>> That's why we cannot currently support:
>> [  hello world  ]
>> [     hello     ]
>> but only:
>> [  hello world  ]
>> [  hello        ]
>>
>> I hope that is all correct :-)
> Looks like. I applied the patch.
> http://forge.scilab.org/index.php/p/jlatexmath/source/commit/84252b89dc9d877395e7bc80c621808748509a8f/

Great.

>> I can also supply an example for (2).
>>
>>>>
>>>> BTW: Could you consider applying the patch from this mail too?
>>>> "[Jlatexmath] Patch: Make basic examples use builder interface"
>>> For now, I added your example
>>>
>>>> http://forge.scilab.org/index.php/p/jlatexmath/source/commit/e848fd52c0f2c3f46b7ea9dcf262ec4b2a2c6c2f/
>>
>> OK.
>>
>> Is there a reason why you don't like adding the builder interface to the
>> examples? IMHO it's more extensible and easier to read.
> ?

"builder" = Builder pattern:
http://en.wikipedia.org/wiki/Builder_pattern  ;-)

> ant example
> builds the example

I was referring to this:
http://lists.scilab.org/pipermail/jlatexmath/2012-December/000115.html
, i.e.:

- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 10);
+ // Note: Old interface for creating icons:
+ //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 10);
+ // Note: New interface using builder pattern (inner class):
+ TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(10).build();


IMHO it is ok to make a 1.0.1 release when this patch is in. There is a
remaining problem that (some?) array environments use the whole width
even with setIsMaxWidth(true), but I don't currently know how to fix
this (and it's not that critical IMHO).  What do you think?

Thanks,
--
Felix Natter
_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Sylvestre Ledru-4 Sylvestre Ledru-4
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Jlatexmath] Option for max. width vs exact width: Remaining Problem

>>>
>>>>>
>>>>> BTW: Could you consider applying the patch from this mail too?
>>>>> "[Jlatexmath] Patch: Make basic examples use builder interface"
>>>> For now, I added your example
>>>>
>>>>> http://forge.scilab.org/index.php/p/jlatexmath/source/commit/e848fd52c0f2c3f46b7ea9dcf262ec4b2a2c6c2f/
>>>
>>> OK.
>>>
>>> Is there a reason why you don't like adding the builder interface to the
>>> examples? IMHO it's more extensible and easier to read.
>> ?
>
> "builder" = Builder pattern:
> http://en.wikipedia.org/wiki/Builder_pattern  ;-)
Oh, sorry :)


>> ant example
>> builds the example
>
> I was referring to this:
> http://lists.scilab.org/pipermail/jlatexmath/2012-December/000115.html
> , i.e.:
>
> - TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 10);
> + // Note: Old interface for creating icons:
> + //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 10);
> + // Note: New interface using builder pattern (inner class):
> + TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(10).build();
Here it is:
http://forge.scilab.org/index.php/p/jlatexmath/source/commit/d5979b533467f46ef93187da7345f81362d82df8/


>
> IMHO it is ok to make a 1.0.1 release when this patch is in.
It is fine for me. Calixte, what is your opinion on this ?

> There is a
> remaining problem that (some?) array environments use the whole width
> even with setIsMaxWidth(true), but I don't currently know how to fix
> this (and it's not that critical IMHO).  What do you think?
We can always see that later.

Sylvestre

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Loading...