Libreoffice Qt5

Posted onby admin
Description of the issue:
On libreoffice-7.0.3.1 it is unable to activate ja-fcitx-mozc.
I successfully set up to run Mozc on other programs such as firefox, atom-ide, and Pluma. So far I got this issue on Libreoffice only.
On Libreoffice you can change a locale from English to Japanese, but you cannot input Japanese characters with Mozc at all. Even input from virtual keyboard is not reflected on Libreoffice.
Steps to reproduce the issue:
Run: sudo pkg install -y ja-fcitx-mozc zh-fcitx-configtool
Run: sudo pkg install -y libreoffice
Open Libreoffice Writer
Run: fcitx
Select Mozc from Input Methond menu on Fcitx tray icon
Expected result:
Mozc should be activated on Libreoffice.
Actual result:
Mozc cannot be activated. Clicking keys on virtual keyboard also does not send characters.
Information:
- Version: FreeBSD 12.2-Release
- Desktop Environment: MATE
Any hints are appreciated.
----
Edit: As my post below shows (https://forums.freebsd.org/threads/...ibreoffice-on-mate-desktop.77864/#post-485727), it seems that this is a compatibility issue between MATE Desktop and Libreoffice with regard to GTK+ 2 support.

View module in:cgit

The past year LibreOffice has sported a Qt5 interface plug-in for better integration with Qt-based environments like a better 'KDE 5' experience. In recent days has been more improvements to this Qt5 integration. Hitting the LibreOffice Git tree over the past week has been initial a11y support (accessibility) while landing today was the initial.

  1. With the LUbuntu distribution 20.04.1 LTS (LXQt 0.14.1), if libreoffice-qt5 is installed, LibreOffice will use it. And this apparently kills printing and PDF exports. After I unistalled libreoffice-qt5, printing and PDF export from under LibreOffice started to work I think OK. I did not have to reinstall the whole LibreOffice for that fix to work.
  2. Za kusintha komwe kulandiridwa. Mu masiku otsiriza pakhala kusintha kwina pakuphatikizika kwa Qt5 kuti ntchitoyi ichitike bwino ndimalo okhala ndi QT5 monga KDE Plasma ndipo tsopano LXQt. Zosintha izi zomwe titha kuwunikira ndi chithandizo choyambirira cha bolodi la Qt5. Tawona zosintha zambiri pa mawonekedwe a plug-in a QT5 / KDE5 Ndi LibreOffice, kuyambira pamenepo, ma code ena.

Visual Class Library (VCL) is responsible for the widgets (windowing, buttons, controls,file-pickers etc.), operating system abstraction, including basic rendering (e.g. the output device).

It should not be confused with Borland’s Visual Component Library, which is entirely unrelated.

VCL provides a graphical toolkit similar to gtk+, Qt, SWING etc.

  • source/

    • the main cross-platform chunk of source
  • inc/

    • cross-platform abstraction headers
  • headless/

    • a backend renderer that draws to bitmaps
  • android/

    • Android backend
  • osx/

    • macOS backend
  • ios/

    • iOS backend
  • quartz/

    • code common to macOS and iOS
  • win/

    • Windows backend
  • qt5/

    • Qt5 (under construction)
  • unx/

    • X11 backend and its sub-platforms
      • gtk3/
        • GTK3 support
      • kf5/
        • KF5 support (based on qt5 VCL plugin mentioned above)
      • gtk3_kde5/
        • GTK3 support with KDE5 file pickers (alternative to native kf5 one)
      • generic/

        • raw X11 support
      • plugadapt/

        • pluggable framework to select correct unx backend
      • dtrans/

        • “data transfer” - clipboard handling
        • http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboardfor tips how to show the current content of theclipboard
  • How the platform abstraction works

    • InitVCL calls ‘CreateSalInstance’
      • this is implemented by the compiled-in platform backend
      • it stores various bits of global state in the‘SalData’ (inc/saldatabasic.hxx) structure but:
    • the SalInstance vtable is the primary outward facing gatewayAPI for platform backends
      • It is a factory for:SalFrames, SalVirtualDevices, SalPrinters,Timers, the SolarMutex, Drag&Drop and otherobjects, as well as the primary event loop wrapper.

Note: references to “SV” in the code mean StarView, which was aportable C++ class library for GUIs, with very old roots, that wasdeveloped by StarDivision. Nowadays it is not used by anything exceptLibreOffice (and OpenOffice).

“svp” stands for “StarView Plugin”.

COM Threading

The way COM is used in LO generally:- vcl puts main thread into Single-threaded Apartment (STA)- oslWorkerWrapperFunction() puts every thread spawned via oslCreateThread() into MTA (free-threaded)

Libreoffice Qt5

GDIMetafile is a vector drawing representation that corresponds directlyto the SVM (StarView Metafile) format; it is extremely important asan intermediate format in all sorts of drawing and printing operations.

There is a class MetafileXmlDump in include/vcl/mtfxmldump.hxx thatcan store a GDIMetafile as XML, which makes debugging much easiersince you can just use “diff” to see changes.

EMF+

emf+ is vector file format used by MSO and is successor of wmf andemf formats. seehttp://msdn.microsoft.com/en-us/library/cc230724.aspx fordocumentation. note that we didn’t have this documentation fromstart, so part of the code predates to the time when we had guessedsome parts and can be enhanced today. there also still many thing notcomplete

Libreoffice vcl qt5

emf+ is handled a bit differently compared to original emf/wmf files,because GDIMetafile is missing features we need (mostly related totransparency, argb colors, etc.)

emf/wmf is translated to GDIMetafile in import filtervcl/source/filter/wmf and so special handling ends here

emf+ is encapsulated into GDIMetafile inside comment records andparsed/rendered later, when it reaches cppcanvas. It is parsed andrendered in cppcanvas/source/mtfrenderer. also note that there areemf+-only and emf+-dual files. dual files contains both types ofrecords (emf and emf+) for rendering the images. these can used alsoin applications which don’t know emf+. in that case we must ignoreemf records and use emf+ for rendering. for more details seethe documentation.

Parsing

wmf/emf filter –> GDI metafile with emf+ in comments –> cppcanvas metafile renderer

lately the GDIMetafile rendering path changed which also influencedemf+ rendering. now many things happen in drawing layer, whereGDIMetafile is translated into drawing layer primitives. formetafiles with emf+ we let the mtfrenderer render them into bitmap(with transparency) and use this bitmap in drawinlayer. cleanersolution for current state would be to extend the drawing layer formissing features and move parsing into drawing layer (might be quitea lot of work). intermediary enhancement would be to know better theneeded size/resolution of the bitmap, before we render emf+ intobitmap in drawing layer. Thorsten is working on the same problem withsvg rendering, so hopefully his approach could be extended for emf+ aswell. the places in drawing layer where we use canvas mtfrenderer torender into bitmaps can be found when you grep for GetUseCanvas. alsolook at vcl/source/gdi/gdimetafile.cxx where you can look forUseCanvas again. moving the parsing into drawinglayer might also havenice side effect for emf+-dual metafiles. in case the emf+ recordsare broken, it would be easier to use the duplicit emfrendering. fortunately we didn’t run into such a broken emf+ fileyet. but there were already few cases where we first though that theproblem might be because of broken emf+ part. so far it always turnedout to be another problem.

Libreoffice

Rendering

before

vcl –> cppcanvas metafile renderer –> vcl

now

drawing layer –> vcl –> cppcanvas metafile renderer –> vcl –> drawing layer

Libreoffice Gtk Theme

another interesting part is actual rendering into canvas bitmap andusing that bitmap later in code using vcl API.

EMF+ implementation has some extensive logging, best if you do a dbgutilbuild, and then

before running LibreOffice; it will give you lots of useful hints.

You can also fallback to EMF (from EMF+) rendering via

Printing/PDF Export

Libreoffice Vcl Qt5

Printing from Writer works like this:

Libreoffice Qt5 Plugin

1) individual pages print by passing an appropriate OutputDevice to XRenderable2) in drawinglayer, a VclMetafileProcessor2D is used to record everything on the page (because the OutputDevice has been set up to record a GDIMetaFile)3) the pages' GDIMetaFiles are converted to PDF by the vcl::PDFWriter in vcl/source/gdi/pdfwriter*

Creating the ODF thumbnail for the first page works as above except step 3 is:

3) the GDIMetaFile is replayed to create the thumbnail

On-screen display differs in step 1 and 2:

1) the VCL Window gets invalidated somehow and paints itself2) in drawinglayer, a VclPixelProcessor2D is used to display the content

Libreoffice Qt

Debugging PDF export

Debugging the PDF export becomes much easier whencompression is disabled (so the PDF file is directly readable) andthe MARK function puts comments into the PDF file about which methodgenerated the following PDF content.

The compression can be disabled even using an env. var:

To de-compress the contents of a PDF file written by a release build orother programs, use the “pdfunzip” tool:

Libreoffice Gtk3

SolarMutexGuard

The solar mutex is the “big kernel lock” of LibreOffice, a global one. It’s arecursive mutex, so it’s allowed to take the lock on the same thread multipletimes, and only the last unlock will actually release the mutex.

UNO methods on components can be called from multiple threads, while themajority of the codebase is not prepared for multi-threading. One way to getaround this mismatch is to create a SolarMutexGuard instance at the start ofeach & every UNO method implementation, but only when it is necessary:

  • Only acquire the SolarMutex if you actually need it (e.g., not in functionsthat return static information).

  • Only around the code that actually needs it (i.e., never call out with itlocked).

This way you ensure that code (not prepared for multithreading) is stillexecuted only on a single thread.

In case you expect that your caller takes the solar mutex, then you can usethe DBG_TESTSOLARMUTEX() macro to assert that in dbgutil builds.

Event listeners are a special (but frequent) case of the “never call out witha mutex (SolarMutex or other) locked” fundamental rule:

  • UNO methods can be called from multiple threads, so most implementationstake the solar mutex as their first action when necessary.

  • This can be problematic if later calling out (an event handler is called),where the called function may be an UNO method implementation as well andmay be invoked on a different thread.

  • So we try to not own the solar mutex, whenever we call out (invoke eventlisteners).

In short, never hold any mutex unless necessary, especially not when callingout.