Detect missing glyphs in text

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

I have written a Python3 appindicator which calls fortune and captures the output for display in the on-screen notification.

Some fortunes contain squares with a hexadecimal number when the corresponding glyph does not exist in the current font. Each square is the representation of the hexadecimal Unicode code point for the missing glyph.

I want to remove the hexadecimal text before I display to the user. I was hoping to find some Python API which would let me inspect text, character by character, to determine something like char.isValidCodePoint() or similar but I cannot find as such.

I found a possible solution that I wanted to investigate here but after installing fonttools via the terminal, my Python program could not import fonttools/fontTools.

Any ideas – either using the Python API or calling out to a terminal?

Update #1: I have since realised the fonttools sample code from the link above will not work for me as it is Python2. I suppose if fonttools could somehow be used, I could invoke a Python2 interpreter from my Python3 script.

Update #2: After lots of reading (see references below), I have since found fc-match but it cannot always uniquely identify the font in use. I obtain the current font in Python:

from gi.repository import Gio
fontName = Gio.Settings( “org.gnome.desktop.interface” ).get_string( “font-name” )

resulting in Ubuntu 11. Passing this result to pango-view along with the hexadecimal character, I get a list of fonts including Ubuntu. To my thinking if the glyph was NOT rendered by the font, the font should not appear in the result from pango-view!

References:

How to find out how fc-match matches?
Find out fallback font used by fontconfig for a certain character
I stared into the fontconfig, and the fontconfig stared back at me

X ITM Cloud News

Marisa

Leave a Reply

Next Post

Indicator of input language on keyboard cursor (or cursor color)

Sat Sep 12 , 2020
Spread the love          Is it possible to have some indication of input language on keyboard cursor (or near it) or maybe change cursor color dependently on input language? I think it would be a great addition for those who use more than one language to input. X ITM Cloud News
X- ITM

Cloud Computing – Consultancy – Development – Hosting – APIs – Legacy Systems

X-ITM Technology helps our customers across the entire enterprise technology stack with differentiated industry solutions. We modernize IT, optimize data architectures, and make everything secure, scalable and orchestrated across public, private and hybrid clouds.

This image has an empty alt attribute; its file name is x-itmdc.jpg

The enterprise technology stack includes ITO; Cloud and Security Services; Applications and Industry IP; Data, Analytics and Engineering Services; and Advisory.

Watch an animation of  X-ITM‘s Enterprise Technology Stack

We combine years of experience running mission-critical systems with the latest digital innovations to deliver better business outcomes and new levels of performance, competitiveness and experiences for our customers and their stakeholders.

X-ITM invests in three key drivers of growth: People, Customers and Operational Execution.

The company’s global scale, talent and innovation platforms serve 6,000 private and public-sector clients in 70 countries.

X-ITM’s extensive partner network helps drive collaboration and leverage technology independence. The company has established more than 200 industry-leading global Partner Network relationships, including 15 strategic partners: Amazon Web Services, AT&T, Dell Technologies, Google Cloud, HCL, HP, HPE, IBM, Micro Focus, Microsoft, Oracle, PwC, SAP, ServiceNow and VMware

.

X ITM