• stevoli

    (@stevoli)


    Not sure what happened with this function, but it doesn’t center vertically or horizontally at all with large elements. They go off the left of the canvas.

    I did some digging and found the functions, and modified them to work correctly if anyone else is having this issue. Basically just remove the realWidth and realHeight variables, and add a line to adjust for the scale_factor.

    editor.js

            wpd_editor.centerObjectH = function (object)
            {
                if (wpd_editor.box_center_x)
                {
                    object.set("left", wpd_editor.box_center_x);                
                }
                else
                {                 
                    var left = parseFloat(wpd.canvas_w) / 2;
                   
                    if (wpd_editor.scale_factor)
                    {                    
                        left = (parseFloat(wpd.canvas_w) * wpd_editor.scale_factor) / 2;
                        left = left / wpd_editor.scale_factor;
                    }                               
                    
                    object.set("left", left);
                }
            }
           wpd_editor.centerObjectV = function (object)
            {
                if (wpd_editor.box_center_y)
                {
                    object.set("top", wpd_editor.box_center_y);
                }
                else
                {  
                    var top = parseFloat(wpd.canvas_h) / 2;
      
                    if (wpd_editor.scale_factor)
                    {
                        top = (parseFloat(wpd.canvas_h) * wpd_editor.scale_factor) / 2;
                        top = top / wpd_editor.scale_factor;
                    }                    
    
                    object.set("top", top);
                }
            }
    • This topic was modified 8 years ago by stevoli.
    • This topic was modified 8 years ago by stevoli.
Viewing 1 replies (of 1 total)
  • Thread Starter stevoli

    (@stevoli)

    Found another issue, after the latest patch. The above code works perfectly on i-text objects, but not on group or path-group objects. The i-text objects seem to be handled differently, you don’t need to subtract 50% of the width.

    The following code seems to fix it at both normal and scaled.

                    var left = (parseFloat(wpd.canvas_w) ) / 2;
    
                    if (wpd_editor.box_center_x)
                        left = wpd_editor.box_center_x - realWidth / 2;
                    //When the responsive mode is enabled, the scale factor already applies  as zoom 
                    //so we remove it before setting the left
                    if (wpd_editor.scale_factor) {
                        left = (parseFloat(wpd.canvas_w) * wpd_editor.scale_factor) / 2;
                        left = left / wpd_editor.scale_factor;                    
                    }
    
                    if(object.type != 'i-text')
                        left = left - (object.getWidth() / 2);                
    
                    object.set("left", left);
    • This reply was modified 8 years ago by stevoli.
Viewing 1 replies (of 1 total)
  • The topic ‘Center Vertical / Horizontal broken’ is closed to new replies.