Hi, On Tue, Sep 12, 2023 at 6:23 AM Lodev <lodev@xxxxxxxxxxxx> wrote: > > Hi, > > Following sos' suggestion, we tried to get Image Preferred DPI from file properties. We thought to use this value directly to draw bitmap. After asking the last question we found a sample in sfx2/source/dialog/dinfdlg.cxx to get this property value. So we added the following code to get the DPI: > > > /* get Image Preferred DPI from File/Properties. User can specify DPI they wanted > * to exported. */ > SfxObjectShell* pDocSh = SfxObjectShell::Current(); > sal_Int32 nImagePreferredDPI = 0; > if (pDocSh) > { > try > { > uno::Reference< lang::XMultiServiceFactory > xFac( pDocSh->GetModel(), uno:: > UNO_QUERY_THROW ); > uno::Reference< beans::XPropertySet > xProps( xFac->createInstance("com.sun. > star.document.Settings"), uno::UNO_QUERY_THROW ); > xProps->getPropertyValue("ImagePreferredDPI") >>= nImagePreferredDPI; > } > catch( uno::Exception& ) > { > } > } > > then sent the nImagePreferredDPI to generate the bitmap. It worked! At least we can use designated DPI to get a better bitmap quality. > > Then when we tried to patch it to latest libreoffice.core and compile it, it failed to link: > > /usr/bin/ld: /home/lodev/git/libreoffice.core/workdir/CxxObject/vcl/source/gdi/vectorgraphicdata.o: in function `convertPrimitive2DSequenceToBitmapEx(std::deque<com::sun::star::uno::Reference<com::sun::star::graphic::XPrimitive2D>, std::allocator<com::sun::star::uno::Reference<com::sun::star::graphic::XPrimitive2D> > > const&, basegfx::B2DRange const&, unsigned int, o3tl::Length, std::optional<Size> const&)': > vectorgraphicdata.cxx:(.text+0x226d): undefined reference to `SfxObjectShell::Current()' > /usr/bin/ld: vectorgraphicdata.cxx:(.text+0x228f): undefined reference to `SfxObjectShell::GetModel() const' > collect2: error: ld returned 1 exit status > make[1]: *** [/home/lodev/git/libreoffice.core/vcl/Library_vcl.mk:20:/home/lodev/git/libreoffice.core/instdir/program/libvcllo.so] 錯誤 1 > > We thought that the time we succeeded should be because the related objects (sfx2) had been there when we tried, so it could compiled and linked successfully. This time we did it from starting so it failed because the object files were no longer there, and we have no idea how to make sfx objects compile first. > > So again we're stuck. We did prove the idea, using Image Preferred DPI to generate better bitmap, works. User can specify a bigger DPI there to get better bitmap resolutions after exporting to OOXML. Just that maybe we shouldn't use sfx object to get the property. But we have no idea how to get the property value since we're not very familiar with the reference things. > > Would anyone please give a little help and hints here? You're looking at the wrong place. Forget "ImagePreferredDPI" for now - this will get relevant once you already have a working solution. The place that is relevant for this is in oox module - more specifically in the drawingml export [1]. The GraphicExport::writeToStorage is very relevant as this is where the call to convert the graphic is made. So this needs changing and you need to find where the document dimensions for the image are and transport that all the way to GraphicExport::writeToStorage. For writer also DocxAttributeOutput::FlyFrameGraphic is relevant (in sw module) and maybe some other cases also, for Impress and Calc something else might be relevant too. [1] oox/source/export/drawingml.cxx > Thanks, Dev Tomaž