0 Replies Latest reply on Jun 3, 2012 7:25 AM by Blatman888

    Font selection view control in Web Gallery

    Blatman888 Level 1

      LR4.1 RC2


      I wanted to be able to change the font type from the UI panel using a font select popup.

      This control really only seems to exist in the inbuilt edit modes (eg: id plate and watermark) so I have tried a workround which seems to work OK so far. Maybe it will help someone else out working with webengines.


      Mac/OSX only at this stage - good source file in Windows may be font.inf but would require a bit of parsing or get a folder listing somehow.

      Basically I read in the contents of the fonts.list file - which appears in the OSX fonts folders - and then massage the contents to get a raw list of the fonts.

      This raw list is then read into a lua table and consumed by the UI popup control.


      Should there be an obvious way that I haven't seen then just give me time to find a banana to eat ... anyway here goes -



      Changing the font type for the cell index numbers.


      Grid cells use cellIndex to give the photo number and in my webengine the css class is .itemNumber       



      Data Model references -   Note:   %s is important for select to work - if %q is used select will work but font won't change ( %q adds quotes to the string ).


                  ["appearance.itemNumber.font"] = function() return string.format( "%s", nonCSS.itemNumberFontSize .. "px " .. nonCSS.itemNumber.font ) end,


                  ["nonCSS.itemNumberFontSize"] = 60,

                  ["nonCSS.itemNumber.font"] = "inherit", 




                  fontlistpath = LrPathUtils.child('/Library/Fonts','')    -- OSX Default fonts




      Code just prior to LR UI Views -


              deffonts = templatepath .. "/pgresources/" .. 'osxdeffont.txt'      -- templatepath is the root path of the webengine - this is the tweaked OSX fonts.list file


              function readFontsFile( deffonts )


                  local fileLines = io.lines( deffonts ) 

                  ff3 = {}           

                  for line in io.lines(deffonts) do

      --   ******************* 

      Filter lines here ...


      eg:   -

                      line = string.sub(line, 17)   -- remove 1st 16 chrs        (/Library/Fonts//Osaka.ttf)

                      line = string.gsub(line, "(.ttf)", "")



      -- ***********************

                      local kline = line

                         local vline = line

                         table.insert(ff3, { title =  kline ,value = vline })





      LR UI View for font select -


                  f:popup_row {

                      title = "Font family :",

                      bindingValue = "nonCSS.itemNumber.font",

                      items =  ff3,

                      bindingEnabled = "appearance.itemNumber.display",   -- control should be disabled if display checkbox false

                      tooltip = "Choose wisely Dave!",




      Using this method is not perfect but gives a good selection of fonts - I found that to improve the success rate the default font file was copied into the webengine

      resources folder and tweaked. eg:  the default file gives Brush Script.ttf but I needed Brush Script MT to work, similarly with Arial Rounded Bold which needed changing

      to Arial Rounded MT Bold


      Basically to find the correct descriptions you could do far worse than to use the ones in the edit selections used by the ID Plate/watermarking features.



                  Well there you go ...


      As an aside I did try an undocumented control which on double click popped up a system font selection dialog (the whole nine yards) but  couldn't get it to link to the css class so I didn't persist - not a good idea to use undocumented controls but can be fun to play with.


          f:font_picker {

              font = "Copperplate",     -- showed font as highlighted when picker opened.

              width = 80,

              value = "Arial",    -- appeared on control (title ??) - this value only changed according to the font selected after double-clicking on another hidden control (f:image_well)

              bindingValue = "nonCSS.itemNumber.font",  -- linkage didn't work




      Again, unless I missed it, it would be really good to have the font_picker documented and working for the web gallery views.  Fonts seem to be a murky area -

      probably accounts for the hassles I am getting with the watermarking feature as well.



      Update :


      If the font doesn't work try using the PostScript name as a value which invariably works.


      eg: Handwriting - Dakota  will not work but Handwriting-Dakota will.

           Arial Bold will not work but Arial-BoldMT will.