Of course, one can easily pass the Font to the subordinate clause as in testDraw/2 and avoid the issue.
Is this a problem with my understanding how fonts work in ViP, or is it a bug?
Code: Select all
GDI+ exception
apiFunctionName = drawStringIn
StatusMessage = ObjectBusy
StatusCode = 4
gdiplusException (gdiplus)
graphics::drawStringIn
pfc\gui\gdiplus\graphics\graphics.pro(539,9)
----------------------------------------
c:\users\hwpra\appdata\roaming\visual prolog\11\pfc\exception\exception.pro(197)
c:\users\hwpra\appdata\roaming\visual prolog\11\pfc\gui\gdiplus\gdiplussupport\gdiplussupport.pro(169)
testdialogf5\testdialogf5.pro(36)
Here is test code to demonstrate the problem:
Code: Select all
predicates
onPaint : window::paintResponder.
clauses
onPaint(_Source, _Rectangle, GDI) :-
HDC = GDI:getNativeGraphicContext(IsReleaseNeeded),
G = graphics::createFromHDC(HDC),
%
F0 = font::createFromHDC(HDC),
G:drawStringAt(F0, solidBrush::create(gdiplus_native::black), gdiplus_native::pointF(5, 5), predicate_fullname(),
stringFormat::create(0, locale_native::lang_english)),
testDraw(G), % Raises exception
% testDraw(G, F0),
%
GDI:releaseNativeGraphicContext(HDC, IsReleaseNeeded).
predicates
testDraw : (graphics G). % either TestMode raises exception
testDraw : (graphics G, font Font).
clauses
testDraw(G) :-
TestMode = 1, % get font from HDC if = 1, % create copy of font from HDC if = 2
HDC = G:getHDC(),
if TestMode = 1 then
Font = font::createFromHDC(HDC)
elseif TestMode = 2 then
% create a copy of the HDC font
HdcFont = font::createFromHDC(HDC),
FF = HdcFont:fontfamily,
Size = HdcFont:size,
FS = HdcFont:style,
Font = font::createFromFontFamily(FF, Size, FS, gdiplus_native::unitPixel)
end if,
S = predicate_fullname(),
G:drawStringAt(Font, solidBrush::create(gdiplus_native::darkRed), gdiplus_native::pointF(40, 40), S,
stringFormat::create(0, locale_native::lang_english)).
testDraw(G, Font) :-
S = predicate_fullname(),
G:drawStringAt(Font, solidBrush::create(gdiplus_native::darkRed), gdiplus_native::pointF(40, 40), S,
stringFormat::create(0, locale_native::lang_english)).