Tuesday, August 7, 2018

When nothing else works...

Few things in life makes me unhappy than a unoptimal or broken system. When my machine does not work at its best I start to suffer itches and bad mood.

Like many other nerds, I can't avoid to update my laptop operating system with the latest developments. No exceptions with Kubuntu 18.04, where I innocently thought it will fix some nasty bugs of 17.10 I was enduring, notably, a very slow desktop login. I took the radical approach, let's format the root partition and install from scratch.

All backups done, machine reinstalled and bingo! now I can't get a second user session, without disconnecting the first. To put in perspective, what is an operating system, especially linux, that can't get more than one user session active at the time?

As usual, Google here, Google there, countless web pages of irrelevant content... and nothing. Greping the syslog, and the culprit was sddm, the login service of Kubuntu. On Github, a report on the issue, but no further indication that the bug will be fixed someday.

Then a hint on the bug report, and it was related to the dual hybrid graphics architecture of the laptop. In my case, I have an Intel and a Radeon dual graphic laptop. The suggestion was to disable the Radeon chip and work only with the Intel, which is no big deal for me. I was happy to finally fix it.

Too easy huh? Not at all. The laptop began to warm too much, even with no CPU load. It was uncomfortable even to rest the hand on the keyboard.

Another set of Google searches and a page in Ubuntu on hybrid graphics. Joining the two solutions, I enabled back the radeon driver, and enabled the switch to let the kernel manage the second graphic chip, so sddm know about it, even if I don't use it.

Second session working, and laptop in normal temperature.





Sunday, June 24, 2018

The Styles Menu and UI Customization

Yesterday I was reviewing a nice feature implemented by the User Experience Team of LibreOffice about the Style menu in WRITER. Like all help pages I review, I must test and explore the feature, looking to get the benefits but also to note the possible pitfalls.

What caught my attention was a nice combination of LibreOffice UI and menu customization. LibreOffice allows documents to carry the customized user interface menus, toolbars and much more. If you have a document that requires a specific set of commands you can customize the user interface in Tools - Customize and store the user interface in your document. When opening the document in another machine with LibreOffice, the user interface carried by the document is displayed. I used this feature professionally when I had to convert some old Excel macros to LibreOffice and the macros had hundreds of lines just to modify the user interface. I drop these lines, did the changes in UI once and stored in the document.



So I applied the same strategy to the Styles menu. I was glad to see that you can format your document with little amount click or by activating the style menu with the keyboard. All my custom style were in the menu.

Then closed my document and opened a new document. I wanted to apply my custom styles as before but hey... it does not work. The custom styles were just doing nothing.

The trick is to customize the Styles menu with your preferred styles and add them to your document instead of the LibreOffice Writer interface (the default). This detail slipped under my nose.



Lessons learned: If you want a document with custom styles in the Styles menu, create a template with your custom styles and custom user interface and each new document based on the template will have everything set up.

Happy Text Styling !

Wednesday, June 20, 2018

LibreOffice Basic well hidden secrets

Last week I wrote a quite long help page on a poorly known feature of LibreOffice aimed to Basic macro programmers.

LibreOffice - since it was named OpenOffice.org long time ago - carried a set of Basic libraries with no documentation (that I was able to find). The libraries were created to support some important features such as Euro conversion or WikiEditor, but also had a set of modules and macro very handy for the ad-hoc or professional Basic programmer of LibreOffice.

The library is distributed in the LibreOffice installers and can be opened in the LibreOffice Macros container, accessible when opening the Basic IDE.





I got fond of the TOOLS library because it has many handy macros that otherwise requires quite a lot of hard code writing and LibreOffice API knowledge even for simple operations.

Things like getting the last used row in a spreadsheet, get the value of a cell, get the filename out of a long URI are the kind of Function's and Sub's we don't want to write again but use GetLastUsedRow, GetValueofCellbyName or FileNameoutofPath for the task.

To use the LibreOffice Tools library , add the statement

GlobalScope.BasicLibraries.LoadLibrary("Tools")

before the first macro of your module. The help page is already online in 

https://help.libreoffice.org/6.1/en-US/text/sbasic/shared/03/lib_tools.html

Note that not every library is described in details in the set of Help pages but if you feel motivated to peek in the code and write a simple description of the remaining modules and macros, join our documentation team!

Happy macro programming!


Tuesday, May 8, 2018

Bringing Localization to New Help UI

As usual, we have a clear vision of the goal we want to achieve and we know it fits perfectly in the framework available, but sometimes we don't get the smart idea the first time you look at the issue.

It was easy to do the proof of concept for the new help and the style sheet transformations, but in the hurry to get the concept, I used a pair of clutches, or plain bad solution, hoping to be able to come back later.

So time has come to fix the localization of the new Help strings, and to work to use the translation infrastructure of The Document Foundation.

The trick was under my eyes for long time. It is called  document() function in XSLT. With the document() function, I can open an external document, and process it while transforming a XML file.

So why not call an auxiliary help file, with all User Interface strings translated, and use the results inside your main transformation? That is what I did in my latest patch, where I created a help file (browserhelp.xhp) with all terms of my User  Interface.

So here is an excerpt of the document() function usage in the XSLT:

<!-- Strings for the help UI page -->
<xsl:variable name="tmp_href_ui"><xsl:value-of select="concat($urlpre,'text/shared/help/browserhelp.xhp')"/></xsl:variable>


<xsl:variable name="tmp_doc_ui" select="document($tmp_href_ui)"/>
 

<xsl:variable name ="ui_contents"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='contents']"/></xsl:variable>

where I get the right location in tmp_href_ui and the document in tmp_doc_ui, and just after I get the string which identifier is 'contents'.

Later, I used the string 'contents' in the page like

<xsl:value-of select="$ui_contents"/>

 VoilĂ . And while we are refactoring, I drop most the the other XSLT I was using as clutch (localized.xsl) and exercised some synapses in using the <xsl:for-each> statement to traverse the list of entries in the languages drop-down selector.

Happy translating!

Monday, May 7, 2018

Screenshots in LibreOffice Help

An image worth a thousands words.

Indeed, a textual description of a software feature is too often hard to read, but a simple picture tells much about.

So I patched the LibreOffice Math help pages with screenshots taken by the ScreenShot_Test helper designed by bubli and added them to the help pages. To avoid handling images in too many scattered help files, I collected the in a new help file named screenshots.xhp under /06/ folder of the module. This way,  the images are embedded at the right page and if the screenshot has to be modifies, it is enough to edit the screenshot.xhp file instead of the target help file, which by the way can be multiple.


The Math module has only 8 screenshots under the module/ folder so it makes it easy to evaluate the impact on the size of the data. For all the supported languages (--with-lang=ALL) it adds 19M bytes of images.

While I was addressing this patch I also had to fix a folder naming issue with the helper, which bubli was so kind to approve and also a fix in the XSLT to handle the special case of the default language, en-US.

See it at work: https://help.libreoffice.org/6.1/en-US/text/smath/01/05030000.html?&DbPAR=MATH&System=UNIX



Thursday, April 26, 2018

Reworking Special Tables in New Help.

Continuing the enhancement of the new help pages, I made some changes in the XSL transformation and CSS file to remove some special tables and sections. In this case I used CSS properties available in HTML5, such as display:flex; .

Many tables were used to position elements in the page. Depending on the CSS class of the table, the purpose of the table changes. Here are the predefined roles worked so far:

onecell: As the name says, the xml table has only one cell. The html table was replaced by a div and proper css, followed by a line break.

icontable: this type of table type is constructed when the first tablecell contains an image. The html table replacement is rendered row by row by a wrapping div with display: flex; attribute and internal divs for the remaining cells in the row.

howtoget: The section "How to get" has now a wrapping div with display: flex;  and flex-direction: columns; to stack the heading and contents divs.


Notes, Tips and Warnings: The special paragraphs were mapped into tables and now are mapped in divs with display:flex;

All divs are also associated with named classes, and therefore the CSS can be tweaked independently.

The remaining tables are left as is but will also undergo some cleanup in the near future.

Happy CSS tweaking!




Monday, April 16, 2018

Fixing the switchinline transform for Help

Last week I spend quite amount of time chasing a bug on the new Help XSL transformation (XSLT) to implement the <switchinline> tag of the Help.

The initial idea was to map the <switchinline> into a javascript <switch> which is a straightforward to implement, but since the devil is in the details, I had hard times to realize that I set the output of a XSL transform as html, and when it comes to javascript, assigning a string to the output of the transform brings many issues.

Specifically, I had the issue when approaching an output like

<![CDATA[case "MAC" : text = "]]>\
<xsl:apply-templates/>\
<![CDATA[");]]>

with the output of the <xsl:apply-templates/> call resulting in strings with carriage return, apostrophes and quotes, which can't be put inside a javascript string unless adding a post processing to remove at least the LF and CR characters. So I implemented the <switchinline> inside a outer wrapping <span> and each each <case> content output into an inner <span> tag.

<span hidden="true" id="{$auxID}">\
<xsl:apply-templates/>\
</span>

Then I played with the "hidden" attribute, emulating the javascript "case" with logic inside the wrapping <span>.