# Unicode and Smart quotes not being drawn properly

**URL:** <https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213>\
**Category:** Coding Questions\
**Created:** [August 6, 2019, 4:00pm UTC](https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213 "2019-08-06T16:00:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![n055](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/n055/32/5466_2.png) [@n055](https://discourse.processing.org/u/n055)\
**Post date:** [August 6, 2019, 4:00pm UTC](https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213/1 "2019-08-06T16:00:20Z")

</div>

I am trying to display text entries by drawing them in my sketch. All of the text I will be using has quotation marks, and the source I am getting them from has them formatted as “curly” or “smart” quotes.  
However, when I loadStrings() from a text file formatted in unicode, and attempt to draw it to the canvas, I get missing characters between each letter:

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/962a5476fc66fa9cc0f0b0c641c2e12a83e97be4.png)

Even when I save the .txt file with ANSI encoding, the smart quotes don’t get drawn properly:

 ![Capture1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/34606e77c3ad91137ff9100512c6711db2b97abf.png)

I have tried with multiple fonts, ones that I know support curly quotes. Is there a way to force Processing to treat Unicode text as ascii or ansi? Is there another fix for this? thanks 🙂

```auto
String[] s;

void setup(){
  size(800, 800);
  fill(0);
  textSize(35);
  textAlign(CENTER, CENTER);
  
  s = loadStrings("testFile.txt");
}

void draw(){
  background(255);
  text(s[0], width / 2, height / 2);
  noLoop();
}

```

the testFile.txt file contains the following text:

> The use of the verb “to fall” (tipol)

I have encoded both as Unicode and ANSI in different trials of my program.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 6, 2019, 4:04pm UTC](https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213/2 "2019-08-06T16:04:03Z")

</div>

> [@n055](#):
>
> Is there another fix for this?

[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#replace(char,char)](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#replace(char,char))

---

<div class="post-metadata">

**Author:** ![n055](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/n055/32/5466_2.png) [@n055](https://discourse.processing.org/u/n055)\
**Post date:** [August 6, 2019, 4:19pm UTC](https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213/3 "2019-08-06T16:19:05Z")

</div>

> [@GoToLoop](#):
>
> [String (Java SE 11 & JDK 11 )](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#replace(char,char))

Just tried this using both possible character notations:

```auto
s[0] = s[0].replace('\u201D', '\"');
 s[0] = s[0].replace('“', '\"');

```

Still the exact same results 😕 Am I using the method incorrectly?

---

<div class="post-metadata">

**Author:** ![n055](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/n055/32/5466_2.png) [@n055](https://discourse.processing.org/u/n055)\
**Post date:** [August 6, 2019, 4:24pm UTC](https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213/4 "2019-08-06T16:24:56Z")

</div>

Update: When I don’t read the strings from a file, and instead just initialize the String within the program, it works fine (even with using smart quotes)

```auto
String s;

void setup(){
  size(800, 800);
  fill(0);
  textSize(35);
  textAlign(CENTER, CENTER);
  
  s = "The use of the verb “to fall” (tipol)";
  //s = s.replace('\u201D', '\"');
  //s = s.replace('“', '\"');
  println(s);
}

void draw(){
  background(255);
  text(s, width / 2, height / 2);
  noLoop();
}

```

![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0c30fc18a90a797b62d301b12cd087d4c9be2749.png)  
Any idea why it’s different when reading from file? And suggestion to how I’d deal with this?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 6, 2019, 6:14pm UTC](https://discourse.processing.org/t/unicode-and-smart-quotes-not-being-drawn-properly/13213/5 "2019-08-06T18:14:27Z")

</div>

> **[loadStrings() / Reference](https://processing.org/reference/loadStrings_.html)**
>
> Reads the contents of a file and creates a String array of its individual lines. If the name of the file is used as the parameter, as in the above example, the file must be loaded in the sketch's "dat…

> Starting with Processing release 0134, all files loaded and saved by the Processing API use UTF-8 encoding. In previous releases, the default encoding for your platform was used, which causes problems when files are moved to other platforms.

![LoadStrings_ANSI___UNICODE](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7596fd67d3cf8b2f669c9abe165de624a2cb38d6.png)

```auto
/**
 * LoadStrings ANSI & UNICODE (v1.0.1)
 * GoToLoop (2019/Aug/06)
 *
 * https://Discourse.Processing.org/t/
 * unicode-and-smart-quotes-not-being-drawn-properly/13213/5
 */

static final String UTF16 = "The use of the verb “to fall” (tipol)";

static final String FILE_ANSI = "testFile.ansi.txt";
static final String FILE_UTF8 = "testFile.utf8.txt";

static final int FONT_SIZE = 030;

String ansi, utf8;

void setup() {
  size(600, 200);
  noLoop();

  colorMode(RGB);
  fill(#FFFF00);

  textMode(MODEL);
  textAlign(CENTER, CENTER);
  textSize(FONT_SIZE);

  ansi = loadStrings(FILE_ANSI)[0];
  utf8 = loadStrings(FILE_UTF8)[0];

  println(UTF16);
  println(int(UTF16.toCharArray())); // [20]: 8220, [28]: 8221

  println(ENTER + ansi);
  println(int(ansi.toCharArray())); // [20]: 65533, [28]: 65533

  println(ENTER + utf8);
  println(int(utf8.toCharArray())); // [20]: 8220, [28]: 8221
}

void draw() {
  background(#0000FF);

  final int cx = width >> 1, cy = height >> 1, qy = height >> 2;
  text(UTF16, cx, qy); // top
  text(ansi, cx, cy); // middle
  text(utf8, cx, 3*qy); // bottom
}

```
