Attila Kovacs 629 Posted August 1, 2020 yippiii, it works. nice one @Mahdi Safsafi Share this post Link to post
pyscripter 689 Posted August 1, 2020 2 minutes ago, Attila Kovacs said: yippiii, it works. nice one @Mahdi Safsafi It does not recolor here. Could you please post your project. Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 ofc some of the const's I had to declare as it did not compile at the beginning, Berlin U2. svg.7z Share this post Link to post
pyscripter 689 Posted August 1, 2020 20 minutes ago, Mahdi Safsafi said: Those are not stored inside vtable ... you need to skip them(don't declare them). Exactly! That's my bad man ... I'm a little bit bad at explaining since I'm not a native English speaker. First step, add all methods in the order they declared(skip all overloaded versions but keep the original). second step for each added method "A" add just after it "A" all its overloaded versions in the order they declared too. Here is how your vtable looks like. The functions seem to work now (Succeeded) but still no recoloring though). What is strange is that the order of the overloads in the VTable is the reverse than that in the include file. What is the tool you are using to inspect the Vtables? Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 (edited) @pyscripter d2missing again without the reformatting, sorry 😉 D2DMissing.7z btw. he is using IDA btw2. RecolorSubtree(Root, D2D1ColorF(1, 0, 0, 0)); should be the other way, 0,0,0,1, rgba Edited August 1, 2020 by Attila Kovacs Share this post Link to post
Guest Posted August 1, 2020 This is the right order as Mahdi shown and this will recolor and get the Paint item right, @Attila Kovacs your last file still reversed. Quote function SetAttributeValue(name: LPWSTR; value: ID2D1SvgAttribute): HResult; overload; stdcall; function SetAttributeValue(name: LPWSTR; _type: D2D1_SVG_ATTRIBUTE_POD_TYPE; value: Pointer; valueSizeInBytes: UINT32): HResult; overload; stdcall; function SetAttributeValue(name: LPWSTR; _type: D2D1_SVG_ATTRIBUTE_STRING_TYPE; value: LPWSTR): HResult; overload; stdcall; function GetAttributeValue(name: LPWSTR; const riid: TGUID; var value: Pointer): HResult; overload; stdcall; function GetAttributeValue(name: LPWSTR; _type: D2D1_SVG_ATTRIBUTE_POD_TYPE; value: Pointer; valueSizeInBytes: UINT32): HResult; overload; stdcall; function GetAttributeValue(name: LPWSTR; _type: D2D1_SVG_ATTRIBUTE_STRING_TYPE; out value: PWideChar; valueCount: UINT32): HResult; overload; stdcall; Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 (edited) @Kas Ob. your version AV's here, I get the recoloring 😄 what now hm, sorry, it works, so declare in reverse order? Edited August 1, 2020 by Attila Kovacs Share this post Link to post
pyscripter 689 Posted August 1, 2020 (edited) @Kas Ob.order which is the same as shown by IDA works here. I can recolor both ways: if Succeeded(Element.GetAttributeValue('fill', D2D1_SVG_ATTRIBUTE_POD_TYPE_COLOR, @OldColor, SizeOf(OldColor))) then begin if (OldColor.r <> 0) or (OldColor.g <> 0) or (OldColor.b <> 0) then Assert(Succeeded(Element.SetAttributeValue('fill', D2D1_SVG_ATTRIBUTE_POD_TYPE_COLOR, @NewColor, SizeOf(NewColor)))); end; and Assert(Succeeded(Element.GetAttributeValue('fill', IID_ID2D1SvgPaint, Pointer(Paint)))); if Assigned(Paint) then begin Paint._AddRef; if Paint.GetPaintType = D2D1_SVG_PAINT_TYPE_COLOR then begin Paint.GetColor(OldColor); if (OldColor.r <> 0) or (OldColor.g <> 0) or (OldColor.b <> 0) then Paint.SetColor(NewColor); end; end; end; The declaration of SetColor needs to be changed: function SetColor(Const color: D2D1_COLOR_F): HResult; stdcall; Edited August 1, 2020 by pyscripter Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 @Kas Ob. is right. With his order this works too: Element.SetAttributeValue('fill', D2D1_SVG_ATTRIBUTE_STRING_TYPE_SVG, '#FF0000'); Share this post Link to post
pyscripter 689 Posted August 1, 2020 (edited) @Attila Kovacs RecolorSubtree(Root, D2D1ColorF(0.5, 80, 80, 80)); does not make sense The Values need to be between 0 and 1 for instance. D2D1ColorF(clRed) = D2D1ColorF(1,0,0,1) I will doing drawing in GrayScale. Does anyone know how to draw the svg with opacity say 0.5? Everything not just the fill color possibly using D2D primitives? Edited August 1, 2020 by pyscripter Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 (edited) @pyscripter yup, was just playing around, it's also RGBA so the original 1, 0, 0, 0 did also not make much sense, mentioned that already earlier Edited August 1, 2020 by Attila Kovacs Share this post Link to post
Mahdi Safsafi 225 Posted August 1, 2020 44 minutes ago, Attila Kovacs said: btw. he is using IDA Not IDA ... its x64dbg 🙂 1 Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 18 minutes ago, pyscripter said: Does anyone know how to draw the svg with opacity say 0.5? Everything not just the fill color possibly using D2D primitives? opacity : single := 0.5; Element.SetAttributeValue('opacity', D2D1_SVG_ATTRIBUTE_POD_TYPE_FLOAT, @opacity, SizeOf(opacity)); where element = 'svg' if this was the question 1 Share this post Link to post
pyscripter 689 Posted August 1, 2020 7 minutes ago, Attila Kovacs said: Element.SetAttributeValue('opacity', D2D1_SVG_ATTRIBUTE_POD_TYPE_FLOAT, @opacity, SizeOf(opacity)); If you do it on the Root it works as expected. Share this post Link to post
Attila Kovacs 629 Posted August 1, 2020 (edited) btw. in the header and also on the screenshot from Mahdi the first parameters are PCWSTR (LPCWSTR) (const) and not always PWSTR (LPWSTR). this however makes no difference, at least at the moment, as they are defined the same in delphi Edited August 1, 2020 by Attila Kovacs 1 Share this post Link to post
Mahdi Safsafi 225 Posted August 1, 2020 20 minutes ago, Attila Kovacs said: btw. in the header and also on the screenshot from Mahdi the first parameters are PCWSTR (LPCWSTR) (const) and not always PWSTR (LPWSTR). this however makes no difference, at least at the moment, as they are defined the same in delphi Good point Attila. It also makes comparing c code against Delphi code much easy. Share this post Link to post
maXcomX 3 Posted August 12, 2020 @pyscripter Did you run the original example from Microsoft in Visual Studio? Share this post Link to post
maXcomX 3 Posted August 17, 2020 (edited) Well after I had a discussion with Microsoft, we came to some conclusions:First of all: The original declaration of ID2D1SvgElement is probably correct!Changing the method order results in multiple errors using the original Microsoft D2DSvgImage sample (with some changes concerning the use of inline functions).The problem probably hints to a wrong D2D1 initialization sequence.For instance: SetAttributeValue should be called before GetAttributeValue at any time!If nothing is set there is nothing to get! And therefore results to a Nil and hresult is 'The parameter is incorrect.' If you want a color, you shuold use the ID2D1SvgPaint interface to retrieve a color, not ID2D1SvgElement.GetAttributeValue!We did an experiment to alter the header as suggested by Pyscripter and run it in VS2019.. Well, that wented out to be a disaster: The MS sample did not work anymore.Most likely the thing is: The Delphi samples (about svg here) are bogus.We wil investigate this issue further on, but until now it points to a wrong usage/implenentation of D2D1. About the Vtable: The correct Vtable should be showed in memory, not by decompiling a dll. Edited August 18, 2020 by maXcomX Share this post Link to post