Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1003809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:02:02+00:00 2026-05-16T08:02:02+00:00

Ligatures are the Unicode characters which are represented by more than one code points.

  • 0

Ligatures are the Unicode characters which are represented by more than one code points. For example, in Devanagari त्र is a ligature which consists of code points त + ् + र.

When seen in simple text file editors like Notepad, त्र is shown as त् + र and is stored as three Unicode characters. However when the same file is opened in Firefox, it is shown as a proper ligature.

So my question is, how to detect such ligatures programmatically while reading the file from my code. Since Firefox does it, there must exist a way to do it programmatically. Are there any Unicode properties which contain this information or do I need to have a map to all such ligatures?

SVG CSS property text-rendering when set to optimizeLegibility does the same thing (combine code points into proper ligature).

PS: I am using Java.

EDIT

The purpose of my code is to count the characters in the Unicode text assuming a ligature to be a single character. So I need a way to collapse multiple code points into a single ligature.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:02:03+00:00Added an answer on May 16, 2026 at 8:02 am

    While Aaron’s answer is not exactly correct, it pushed me in the right direction. After reading through the Java API docs of java.awt.font.GlyphVector and playing a lot on the Clojure REPL, I was able to write a function which does what I want.

    The idea is to find the width of glyphs in the glyphVector and combine the glyphs with zero width with the last found non-zero width glyph. The solution is in Clojure but it should be translatable to Java if required.

    (ns net.abhinavsarkar.unicode
      (:import [java.awt.font TextAttribute GlyphVector]
               [java.awt Font]
               [javax.swing JTextArea]))
    
    (let [^java.util.Map text-attrs {
            TextAttribute/FAMILY "Arial Unicode MS"
            TextAttribute/SIZE 25
            TextAttribute/LIGATURES TextAttribute/LIGATURES_ON}
          font (Font/getFont text-attrs)
          ta (doto (JTextArea.) (.setFont font))
          frc (.getFontRenderContext (.getFontMetrics ta font))]
      (defn unicode-partition
        "takes an unicode string and returns a vector of strings by partitioning
        the input string in such a way that multiple code points of a single
        ligature are in same partition in the output vector"
        [^String text]
        (let [glyph-vector 
                (.layoutGlyphVector
                  font, frc, (.toCharArray text),
                  0, (.length text), Font/LAYOUT_LEFT_TO_RIGHT)
              glyph-num (.getNumGlyphs glyph-vector)
              glyph-positions
                (map first (partition 2
                              (.getGlyphPositions glyph-vector 0 glyph-num nil)))
              glyph-widths
                (map -
                  (concat (next glyph-positions)
                          [(.. glyph-vector getLogicalBounds width)])
                  glyph-positions)
              glyph-indices 
                (seq (.getGlyphCharIndices glyph-vector 0 glyph-num nil))
              glyph-index-width-map (zipmap glyph-indices glyph-widths)
              corrected-glyph-widths
                (vec (reduce
                        (fn [acc [k v]] (do (aset acc k v) acc))
                        (make-array Float (count glyph-index-width-map))
                        glyph-index-width-map))]
          (loop [idx 0 pidx 0 char-seq text acc []]
            (if (nil? char-seq)
              acc
              (if-not (zero? (nth corrected-glyph-widths idx))
                (recur (inc idx) (inc pidx) (next char-seq)
                  (conj acc (str (first char-seq))))
                (recur (inc idx) pidx (next char-seq)
                  (assoc acc (dec pidx)
                    (str (nth acc (dec pidx)) (first char-seq))))))))))
    

    Also posted on Gist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't recommend any particular one. If you want just… May 16, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer Your machine is little-endian, and least significant bytes go first. May 16, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer At the moment, no one is positive, but the evidence… May 16, 2026 at 5:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

What methods are there to transform a PDF to HTML? It could be anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.