I think you have more convenience checking the entire class, as in the 
attached txt file.
Notice that normalButtonSize=48 for iPad II simulator skin (and so it seems 
for the real device).
Regards

Il giorno martedì 4 maggio 2021 alle 03:56:13 UTC+2 Shai Almog ha scritto:

> What's in the paint() method of SaveIconSoliciting()?
>
> On Monday, May 3, 2021 at 9:37:26 AM UTC+3 P5music wrote:
>
>> Maybe you answered to another thread by mistake.
>> This is what my problem is:
>> I created icons in my app by means of the Flamingo tool. They originate 
>> from svg files and then they become Java classes. It is so also because 
>> some new icons are created, and also they have to be injected in HTML.
>>
>> I am not using material font in this case.
>> The images resemble the material icons but as you can see in the example 
>> the icon is a new one, it is modified, so it is assigned to the button like 
>> an image.
>>
>> The image (I am referring to the object) has the right size, but the 
>> drawing, or the scaling, or whatever internal method is doing something 
>> wrong.
>> Indeed just a tiny part is visible of the original shape, because it is 
>> in big size (but in normal viewport size), as you can see in the detail of 
>> the attached image.
>>
>> Regards
>> Il giorno lunedì 3 maggio 2021 alle 03:58:32 UTC+2 Shai Almog ha scritto:
>>
>>> I don't understand the logic of your app here.
>>> You're scaling a font icon. 
>>> Converting it to a non-scalable png.
>>> Then placing that in a self scaling button to scale again.
>>>
>>> I suggest isolating this to a runnable test case.
>>>
>>> On Sunday, May 2, 2021 at 10:29:07 AM UTC+3 P5music wrote:
>>>
>>>> No, normalButtonSize is not huge. Maybe my written explanation was not 
>>>> clear enough in regard of the images.
>>>>
>>>> As you can see from the attached images the buttons have the right 
>>>> size, so
>>>> I can say that
>>>> the image itself is not huge, but the internal drawing is out of scale 
>>>> so
>>>>
>>>> the resulting picture has the right size but it depicts only a small 
>>>> fraction of the total area of the drawing.
>>>>
>>>> You can see that in one image in particular a detail is "magnified", so 
>>>> you recognize the shape of the icon and it is clear that
>>>> it is like 
>>>> the image is huge but the viewport just shows a portion of it.
>>>>
>>>> The viewport is the button
>>>> and it is the size of the resulting image: 
>>>> it has the right size in pixels but the drawing exceedes it.
>>>> Regards
>>>> Il giorno domenica 2 maggio 2021 alle 03:37:11 UTC+2 Shai Almog ha 
>>>> scritto:
>>>>
>>>>> What's normalButtonSize ?
>>>>> I'm assuming it's huge on iOS.
>>>>>
>>>>> On Saturday, May 1, 2021 at 5:36:05 PM UTC+3 P5music wrote:
>>>>>
>>>>>> Here are the images (see previous message)
>>>>>> Regards
>>>>>> Il giorno sabato 1 maggio 2021 alle 14:09:35 UTC+2 P5music ha scritto:
>>>>>>
>>>>>>> My CN1 app has some buttons on the interface with images created 
>>>>>>> with the Flamingo tool, that is, they are created in Java code from SVG 
>>>>>>> files.
>>>>>>> On the simulator and on Android the user interface is almost good, 
>>>>>>> with right buttons image (see attached image 
>>>>>>> right_button_image_dimension_example.png)
>>>>>>>
>>>>>>> On iOS the buttons have the right size but the images are huge or 
>>>>>>> tiny
>>>>>>> (see attached image wrong_button_image_dimension_example
>>>>>>> for the huge case)
>>>>>>>
>>>>>>> This is the code for the most recognizable one:
>>>>>>> saveIconImageSoliciting=new 
>>>>>>> SaveIconSoliciting().scaled(normalButtonSize,
>>>>>>> normalButtonSize).toImage();
>>>>>>> saveButton=new ScaleImageButton(saveIconImageSoliciting);
>>>>>>> where
>>>>>>> SaveIconSoliciting is the class created by Flamingo.
>>>>>>>
>>>>>>> see also these thread
>>>>>>>
>>>>>>> https://groups.google.com/g/codenameone-discussions/c/K94DFhApfRY/m/CD3ISV3RBgAJ
>>>>>>> Can my app be affected by that on iOS?
>>>>>>> Otherwise what could be the cause and how to fix?
>>>>>>> Thanks in advanvce
>>>>>>>
>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/1b3a835c-196b-47e9-8c17-72a473f115e8n%40googlegroups.com.
import com.codename1.ui.*;
import com.codename1.ui.geom.*;

public class SaveIconSoliciting extends Image implements Painter {
    private int width, height;
    private Transform t = Transform.makeIdentity(), t2 = 
Transform.makeIdentity();

    public SaveIconSoliciting() {
        super(null);
        width = getOrigWidth();
        height = getOrigHeight();
    }

    public SaveIconSoliciting(int width, int height) {
        super(null);
        this.width = width;
        this.height = height;
        fixAspectRatio();
    }
            
    @Override
    public int getWidth() {
        return width;
    }

    @Override
    public int getHeight() {
        return height;
    }

    @Override
    public void scale(int width, int height) {
        this.width = width;
        this.height = height;
        fixAspectRatio();
    }

    @Override
    public SaveIconSoliciting scaled(int width, int height) {
        SaveIconSoliciting f = new SaveIconSoliciting(width, height);
        f.fixAspectRatio();
        return f;
    }

    public Image toImage() {
        Image i = Image.createImage(width, height, 0);
        Graphics g = i.getGraphics();
        drawImage(g, null, 0, 0, width, height);
        return i;
    }

    private void fixAspectRatio() {
        if(width == -1) {
            float ar = ((float)getOrigWidth()) / ((float)getOrigHeight());
            width = Math.round(((float)height) * ar);
        }
        if (height == -1) {
            float ar = ((float)getOrigHeight()) / ((float)getOrigWidth());
            height = Math.round(((float)width) * ar);
        }
    }

    @Override
    public Image fill(int width, int height) {
        return new SaveIconSoliciting(width, height);
    }

    @Override
    public Image applyMask(Object mask) {
        return new SaveIconSoliciting(width, height);
    }

    @Override
    public boolean isAnimation() {
        return true;
    }

    @Override
    public boolean requiresDrawImage() {
        return true;
    }

    @Override
    protected void drawImage(Graphics g, Object nativeGraphics, int x, int y) {
        drawImage(g, nativeGraphics, x, y, width, height);
    }

    @Override
    protected void drawImage(Graphics g, Object nativeGraphics, int x, int y, 
int w, int h) {
        g.getTransform(t);
        t2.setTransform(t);
        float hRatio = ((float) w) / ((float) getOrigWidth());
        float vRatio = ((float) h) / ((float) getOrigHeight());
        t2.translate(x + g.getTranslateX(), y + g.getTranslateY());
        t2.scale(hRatio, vRatio);
        g.setTransform(t2);
        paint(g);
        g.setTransform(t);
    }

    private static void paint(Graphics g) {
        int origAlpha = g.getAlpha();
        Stroke baseStroke;
        Shape shape;
        g.setAntiAliased(true);
        g.setAntiAliasedText(true);
        /*Composite origComposite = g.getComposite();
        if (origComposite instanceof AlphaComposite) {
            AlphaComposite origAlphaComposite = (AlphaComposite)origComposite;
            if (origAlphaComposite.getRule() == AlphaComposite.SRC_OVER) {
                origAlpha = origAlphaComposite.getAlpha();
            }
        }
        */
        java.util.LinkedList<Transform> transformations = new 
java.util.LinkedList<Transform>();
        

        // 

        // _0

        // _0_0
        shape = new GeneralPath();
        ((GeneralPath) shape).moveTo(152.20505, 95.92753);
        ((GeneralPath) shape).lineTo(152.20505, 151.92754);
        ((GeneralPath) shape).lineTo(40.20505, 151.92754);
        ((GeneralPath) shape).lineTo(40.20505, 95.92753);
        ((GeneralPath) shape).lineTo(24.205051, 95.92753);
        ((GeneralPath) shape).lineTo(24.205051, 151.92754);
        ((GeneralPath) shape).curveTo(24.205051, 160.72754, 31.405052, 
167.92754, 40.20505, 167.92754);
        ((GeneralPath) shape).lineTo(152.20505, 167.92754);
        ((GeneralPath) shape).curveTo(161.00505, 167.92754, 168.20505, 
160.72754, 168.20505, 151.92754);
        ((GeneralPath) shape).lineTo(168.20505, 95.92753);
        ((GeneralPath) shape).closePath();
        ((GeneralPath) shape).moveTo(104.20505, 101.28753);
        ((GeneralPath) shape).lineTo(124.92505, 80.64752);
        ((GeneralPath) shape).lineTo(136.20505, 91.92752);
        ((GeneralPath) shape).lineTo(96.20505, 131.92752);
        ((GeneralPath) shape).lineTo(56.205048, 91.92753);
        ((GeneralPath) shape).lineTo(67.48505, 80.64753);
        ((GeneralPath) shape).lineTo(88.20505, 101.28754);
        ((GeneralPath) shape).lineTo(88.20505, 23.927525);
        ((GeneralPath) shape).lineTo(104.20505, 23.927525);
        ((GeneralPath) shape).closePath();

        g.setColor(0);
        g.fillShape(shape);

        // _0_1

        // _0_2
        shape = new GeneralPath();
        ((GeneralPath) shape).moveTo(24.205051, 28.428568);
        ((GeneralPath) shape).lineTo(24.205051, 35.92753);
        ((GeneralPath) shape).lineTo(31.70401, 35.92753);
        ((GeneralPath) shape).lineTo(53.82094, 13.810597);
        ((GeneralPath) shape).lineTo(46.32198, 6.311637);
        ((GeneralPath) shape).closePath();
        ((GeneralPath) shape).moveTo(59.620132, 8.011407);
        ((GeneralPath) shape).curveTo(60.400024, 7.231517, 60.400024, 5.971687, 
59.620132, 5.191797);
        ((GeneralPath) shape).lineTo(54.94078, 0.5124469);
        ((GeneralPath) shape).curveTo(54.16089, -0.26744312, 52.901062, 
-0.26744312, 52.12117, 0.5124469);
        ((GeneralPath) shape).lineTo(48.461678, 4.171937);
        ((GeneralPath) shape).lineTo(55.960636, 11.670897);
        ((GeneralPath) shape).closePath();

        g.fillShape(shape);


        g.setAlpha(origAlpha);
    }

    /**
     * Returns the X of the bounding box of the original SVG image.
     * 
     * @return The X of the bounding box of the original SVG image.
     */
    public static int getOrigX() {
        return 25;
    }

    /**
     * Returns the Y of the bounding box of the original SVG image.
     * 
     * @return The Y of the bounding box of the original SVG image.
     */
    public static int getOrigY() {
        return 0;
    }

    /**
     * Returns the width of the bounding box of the original SVG image.
     * 
     * @return The width of the bounding box of the original SVG image.
     */
    public static int getOrigWidth() {
        return 192;
    }

    /**
     * Returns the height of the bounding box of the original SVG image.
     * 
     * @return The height of the bounding box of the original SVG image.
     */
    public static int getOrigHeight() {
        return 192;
    }

    @Override
    public void paint(Graphics g, Rectangle rect) {
        drawImage(g, null, rect.getX(), rect.getY(), rect.getWidth(), 
rect.getHeight());
    }
}

Reply via email to