PDA

View Full Version : getImageSize() missing in FGU



celestian
October 22nd, 2020, 15:21
Seems like getImageSize() is not in FGU at this time?



local w = Interface.openWindow("imagewindow",nodeImage);
if w then
local ctrl = w.createControl("image_refblock", "image");
Debug.console("manager_author_adnd.lua","createBlockImage","window (w)",w);
Debug.console("manager_author_adnd.lua","createBlockImage","ctrl",ctrl);
nXOriginal, nYOriginal = ctrl.getImageSize();
nX, nY = getAdjustedImageSize(win,ctrl);
w.close();
end



The above code fails when the values "w" and "ctrl" seem valid.



[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'sImageNode' | s'image.id-00002'
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'sImageCaption' | s'Image tsr'
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'nodeImage' | databasenode = { image.id-00002 }
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'window (w)' | windowinstance = { class = imagewindow, node = image.id-00002, x,y,w,h = 658,44,778,765 }
[10/20/2020 5:09:50 PM] s'manager_author_adnd.lua' | s'createBlockImage' | s'ctrl' | genericcontrol = { name = s'image', x,y,w,h = 0,0,0,0 }
[10/20/2020 5:09:50 PM] [<color="red">ERROR</color>] Script execution error: [string "scripts/manager_author_adnd.lua"]:398: attempt to call field 'getImageSize' (a nil value)


Same output in FGC except getImageSize() works.

If there is a better method to collect this data now I'd be happy to switch to it. I always thought loading the image to get the image size then closing it was a bit... clunky. The reason I do this is to find out the size of the image, adjust so that it fits within the requirements for inline image views in a ref-manual.

LordEntrails
October 22nd, 2020, 15:41
I don't think images have a size anymore. If I'm right, this is because images are compilations of assets and the image canvas itself is infinitely large. This is a supposition, but it seems to fit your issue.

Moon Wizard
October 22nd, 2020, 22:52
If you are using the latest version of FGU and CoreRPG ruleset; the image_refblock is no longer an imagecontrol. Instead, it is implemented in FGU as a genericcontrol using a new setAsset API we're trying out for improved performance in reference manuals. So, getImageSize is not valid on the new template which uses a genericcontrol.

Regards,
JPG

celestian
October 23rd, 2020, 02:41
If you are using the latest version of FGU and CoreRPG ruleset; the image_refblock is no longer an imagecontrol. Instead, it is implemented in FGU as a genericcontrol using a new setAsset API we're trying out for improved performance in reference manuals. So, getImageSize is not valid on the new template which uses a genericcontrol.

Regards,
JPG

Not entirely clear, so you're saying there isn't a method to get the image size yet? Or that there is some mechanism within the "genericcontrol" ? I did a quick search of the doc site and didn't get a hit on setAsset(). What I did see in CoreRPG 3.3.12 didn't clear up my mind on how to do it either ;(

Moon Wizard
October 23rd, 2020, 02:57
It's a brand new API that is still in testing that enhances genericcontrols to be able to display an "asset" fitted within the control area.

There is no mechanism to get the image size from the genericcontrol. The assumption is that the control is set to the desired size; and the asset is scaled to fit within that space regardless of it's actual size.

JPG

celestian
October 23rd, 2020, 16:08
It's a brand new API that is still in testing that enhances genericcontrols to be able to display an "asset" fitted within the control area.

There is no mechanism to get the image size from the genericcontrol. The assumption is that the control is set to the desired size; and the asset is scaled to fit within that space regardless of it's actual size.

JPG

Okay, I'll wait about for docs and/or update on how this works. The way the extension works currently is to get the image size and if it's bigger than the "best practices" it scales it down to fit in that for the ref-manual and is set in the nodeBlock.

Moon Wizard
October 23rd, 2020, 18:51
I'll add a genericcontrol.getAsset API and an Interface.getAssetSize API to the next release build that you can use to query the asset name and then the size of an asset.

Regards,
JPG

celestian
April 21st, 2021, 22:54
I'll add a genericcontrol.getAsset API and an Interface.getAssetSize API to the next release build that you can use to query the asset name and then the size of an asset.

Regards,
JPG

Did this ever get added? I still have a need to re-implement the code from FGC...

(trimmed out and compacted this for simplicity, these are the key fragments so there is a work process to follow, the key issue is the size)



local sNoteText = DB.getValue(nodeStory,"text","");

local sPatternMatchFGU = '<linklist><link class="imagewindow" recordname="[^\"]+">[^<]+</link></linklist>';
local sPatternMatchFGC = '<linklist>[^<]+<link class="imagewindow" recordname="[^\"]+">[^<]+</link>[^<]+</linklist>';
local sPatternMatch = sPatternMatchFGC;

if UtilityManager.isClientFGU() then
sPatternMatch = sPatternMatchFGU;
end

local nStart, nEnd = string.find(sNoteText,sPatternMatch,1);
local sText= string.sub(sNoteText,nStart,nEnd);

local sImageNode = sText:match("recordname=\"([^\"]+)\"");
local sImageCaption = sText:match("<link class=\"imagewindow\" recordname=\"[^\"]+\">([^<]+)</link>");

local nodeImage = DB.findNode(sImageNode);
local w = Interface.openWindow("imagewindow",nodeImage);
if w then
if not UtilityManager.isClientFGU() then
local ctrl = w.createControl("image_refblock", "image");
local nXX,nYY = ctrl.getImageSize();
nX, nY = getAdjustedImageSize(nXX,nYY);
else
....



Into FGU so inline images will work as expected using the Author conversion tool.

celestian
April 21st, 2021, 23:23
Actually it looks like :



local sAsset = DB.getText(w.getDatabaseNode(), "image", "");
local nAssetX, nAssetY = Interface.getAssetSize(sAsset);


Works.