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 8868687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:19:31+00:00 2026-06-14T17:19:31+00:00

The client prints labels and has been using a set of symbolic (?) fonts

  • 0

The client prints labels and has been using a set of symbolic (?) fonts to do this. The application uses a single byte database (Oracle with Latin-1). The old application I am replacing was not Unicode aware. It somehow did OK. The replacement application I am writing is supposed to handle the old data.

The symbols picked from the charmap application often map to particular Unicode characters, but sometimes they don’t. What looks like the Moon using the LAB3 font, for example, is in fact U+2014 (EM DASH). When users paste this character into a Swing text field, the character has the code point 8212. It was “moved” into the Private Use Area (by Windows? Java?). When saving this character to the database, Oracle decides that it cannot be safely encoded and replaces it with the dreaded ¿. Thus, I started shifting the characters by 8000: -= 8000 when saving, += 8000 when displaying the field. Unfortunately I discovered that other characters were not shifted by the same amount. In one particular font, for example, ž has the code point 382, so I shifted it by +/-256 to “fix” it.

By now I’m dreading the discovery of more strange offsets and I wonder: Can I get at this mapping using Java? Perhaps the TTF font has a list of the 255 glyphs it encodes and what Unicode characters those correspond to and I can do it “right”?

Right now I’m using the following kludge:

static String fromDatabase(String str, String fontFamily) {

  if (str != null && fontFamily != null) {
    Font font = new Font(fontFamily, Font.PLAIN, 1);

    boolean changed = false;
    char[] chars = str.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      if (font.canDisplay(chars[i] + 0xF000)) {
        // WE8MSWIN1252 + WinXP
        chars[i] += 0xF000;
        changed = true;
      }
      else if (chars[i] >= 128 && font.canDisplay(chars[i] + 8000)) {
        // WE8ISO8859P1 + WinXP
        chars[i] += 8000;
        changed = true;
      }
      else if (font.canDisplay(chars[i] + 256)) {
        // ž in LAB1 Eastern = 382
        chars[i] += 256;
        changed = true;
      }
    }
    if (changed) str = new String(chars);
  }
  return str;
}

static String toDatabase(String str, String fontFamily) {

  if (str != null && fontFamily != null) {
    boolean changed = false;
    char[] chars = str.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      int chr = chars[i];
      if (chars[i] > 0xF000) {
        // WE8MSWIN1252 + WinXP
        chars[i] -= 0xF000;
        changed = true;
      }
      else if (chars[i] > 8000) {
        // WE8ISO8859P1 + WinXP
        chars[i] = (char) (chars[i] - 8000);
        changed = true;
      }
      else if (chars[i] > 256) {
        // ž in LAB1 Eastern = 382
        chars[i] = (char) (chars[i] - 256);
        changed = true;
      }
    }
    if (changed) return new String(chars);
  }

  return str;
}
  • 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-06-14T17:19:32+00:00Added an answer on June 14, 2026 at 5:19 pm

    Just to provide closure, here’s what seems to work:

    static String fromDatabase(String str, String fontFamily) {
      if (str != null && fontFamily != null) {
        try {
          byte[] bytes = str.getBytes("ISO-8859-1"); // database encoding
          if (fontFamily.startsWith("LAB")) {
            str = new String(bytes, "Windows-1252");
          }
        }
        catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
      }
      return str;
    }
    
    static String toDatabase(String str, String fontFamily) {
      if (str != null && fontFamily != null) {
        try {
          if (fontFamily.startsWith("LAB")) {
            str = new String(str.getBytes("Windows-1252"), "ISO-8859-1");
          }
        }
        catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
      }
      return str;
    }
    
    public void exportFormData(EigentumsbezeichnungInformationFormData formData) throws ProcessingException {
      super.exportFormData(formData);
      formData.getWert().setValue(toDatabase(formData.getWert().getValue(), formData.getSchrift().getValue()));
    }
    
    public void importFormData(EigentumsbezeichnungInformationFormData formData) throws ProcessingException {
      super.importFormData(formData);
      getWertField().setValue(fromDatabase(formData.getWert().getValue(), formData.getSchrift().getValue()));
    }
    

    Here’s my explanation: The database uses ISO 8859-1 (aka. Latin 1). Ten years ago, the client commissioned a bunch of special fonts that deliberately say that they are Latin-1 encoded, but in fact they show different characters. Notice how the Omega in this example takes the place of Ù!

    charmap screenshot to illustrate the mapping

    Furthermore, some of the characters not used by Latin-1 are also used. The easiest solution seems to assume that the correponding Windows code page is being used. This allows Java to transcode the bytes from the database “fake Windows-1252” into Unicode and back. After translation, the Swing application will display a Ù using the font which shows the Omega glyph. Problem “solved.”

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

Sidebar

Related Questions

I have a Python client-server application and its server has been running for about
I am working on a client-server application that uses boost::serialization library for it's serialization
Our VB WinForms application prints a series reports using the standard PrintDocument object, some
I'm using this calendar plugin to display my client's agenda using a mySQL db.
I am using Tkinter to help me build a FTP client, in this client
In the example below, if client code using GetPeople wanted to print the name
Client side form validation becomes easiest by using jQuery. I tried all validators and
I'm trying to port an application from using HAL to using pure udev. It
I have a very critial business application presently running using Winforms. The application is
Possible Duplicate: Scanner issue when using nextLine after nextInt I am creating a client

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.