diff -Naur graphics-master/dune-project graphics-master-utf-8/dune-project
--- graphics-master/dune-project	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/dune-project	2024-04-26 22:49:29.628431182 +0200
@@ -1,5 +1,5 @@
 (lang dune 2.7)
-(name graphics)
+(name graphicx)
 
 (generate_opam_files true)
 
@@ -14,7 +14,7 @@
 (documentation https://ocaml.github.io/graphics/)
 
 (package
- (name graphics)
+ (name graphicx)
  (depends
    "dune-configurator"
   ("conf-libX11" (<> :os win32))
diff -Naur graphics-master/graphics.opam graphics-master-utf-8/graphics.opam
--- graphics-master/graphics.opam	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/graphics.opam	1970-01-01 01:00:00.000000000 +0100
@@ -1,41 +0,0 @@
-# This file is generated by dune, edit dune-project instead
-opam-version: "2.0"
-synopsis: "The OCaml graphics library"
-description: """
-The graphics library provides a set of portable drawing
-primitives. Drawing takes place in a separate window that is created
-when Graphics.open_graph is called.
-
-This library used to be distributed with OCaml up to OCaml 4.08.
-"""
-maintainer: ["jeremie@dimino.org" "david.allsopp@metastack.com"]
-authors: [
-  "Xavier Leroy" "Jun Furuse" "J-M Geffroy" "Jacob Navia" "Pierre Weis"
-]
-license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
-homepage: "https://github.com/ocaml/graphics"
-doc: "https://ocaml.github.io/graphics/"
-bug-reports: "https://github.com/ocaml/graphics/issues"
-depends: [
-  "dune" {>= "2.7"}
-  "dune-configurator"
-  "conf-libX11" {os != "win32"}
-  "conf-pkg-config" {os != "win32"}
-  "ocaml" {>= "4.09.0~~"}
-  "odoc" {with-doc}
-]
-build: [
-  ["dune" "subst"] {dev}
-  [
-    "dune"
-    "build"
-    "-p"
-    name
-    "-j"
-    jobs
-    "@install"
-    "@runtest" {with-test}
-    "@doc" {with-doc}
-  ]
-]
-dev-repo: "git+https://github.com/ocaml/graphics.git"
diff -Naur graphics-master/graphicx.opam graphics-master-utf-8/graphicx.opam
--- graphics-master/graphicx.opam	1970-01-01 01:00:00.000000000 +0100
+++ graphics-master-utf-8/graphicx.opam	2024-04-26 22:49:29.628431182 +0200
@@ -0,0 +1,41 @@
+# This file is generated by dune, edit dune-project instead
+opam-version: "2.0"
+synopsis: "The OCaml graphics library"
+description: """
+The graphics library provides a set of portable drawing
+primitives. Drawing takes place in a separate window that is created
+when Graphics.open_graph is called.
+
+This library used to be distributed with OCaml up to OCaml 4.08.
+"""
+maintainer: ["jeremie@dimino.org" "david.allsopp@metastack.com"]
+authors: [
+  "Xavier Leroy" "Jun Furuse" "J-M Geffroy" "Jacob Navia" "Pierre Weis"
+]
+license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
+homepage: "https://github.com/ocaml/graphics"
+doc: "https://ocaml.github.io/graphics/"
+bug-reports: "https://github.com/ocaml/graphics/issues"
+depends: [
+  "dune" {>= "2.7"}
+  "dune-configurator"
+  "conf-libX11" {os != "win32"}
+  "conf-pkg-config" {os != "win32"}
+  "ocaml" {>= "4.09.0~~"}
+  "odoc" {with-doc}
+]
+build: [
+  ["dune" "subst"] {dev}
+  [
+    "dune"
+    "build"
+    "-p"
+    name
+    "-j"
+    jobs
+    "@install"
+    "@runtest" {with-test}
+    "@doc" {with-doc}
+  ]
+]
+dev-repo: "git+https://github.com/ocaml/graphics.git"
diff -Naur graphics-master/src/dune graphics-master-utf-8/src/dune
--- graphics-master/src/dune	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/src/dune	2024-04-26 22:50:21.428937263 +0200
@@ -18,14 +18,15 @@
   Printf.ksprintf send
     {|
 (library
- (public_name graphics)
+ (public_name graphicx)
  (wrapped false)
  (synopsis "Portable drawing primitives")
  (foreign_stubs
   (language c)
   (names %s)
-  (flags (:include cflags)))
- (c_library_flags (:include libs)))
+  (flags (:include cflags) -I/opt/X11/include))
+ (c_library_flags (:include libs) -L/opt/X11/lib -lX11 )
+)
 
 (copy_files# %s/*)
 
diff -Naur graphics-master/src/unix/events.c graphics-master-utf-8/src/unix/events.c
--- graphics-master/src/unix/events.c	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/src/unix/events.c	2024-04-26 22:49:29.628431182 +0200
@@ -94,8 +94,6 @@
       XFillRectangle(caml_gr_display, newbstore.win, newbstore.gc,
                      0, 0, newbstore.w, newbstore.h);
       XSetForeground(caml_gr_display, newbstore.gc, caml_gr_color);
-      if (caml_gr_font != NULL)
-        XSetFont(caml_gr_display, newbstore.gc, caml_gr_font->fid);
 
       /* Copy the old backing store into the new one */
       XCopyArea(caml_gr_display, caml_gr_bstore.win, newbstore.win,
diff -Naur graphics-master/src/unix/libgraph.h graphics-master-utf-8/src/unix/libgraph.h
--- graphics-master/src/unix/libgraph.h	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/src/unix/libgraph.h	2024-04-26 22:49:29.628431182 +0200
@@ -37,7 +37,8 @@
 extern Bool caml_gr_remember_modeflag;    /* Remember-mode flag */
 extern int caml_gr_x, caml_gr_y;      /* Coordinates of the current point */
 extern int caml_gr_color;        /* Current *CAML* drawing color (can be -1) */
-extern XFontStruct * caml_gr_font;    /* Current font */
+extern XFontSet font_set;    /* Current font_set */
+
 extern long caml_gr_selected_events;  /* Events we are interested in */
 extern Bool caml_gr_ignore_sigio;     /* Whether to consume events on sigio */
 extern Atom caml_wm_delete_window;    /* "WM_DELETE_WINDOW" atom */
@@ -54,13 +55,13 @@
 #define min(a,b) ((a) < (b) ? (a) : (b))
 #define max(a,b) ((a) > (b) ? (a) : (b))
 
-#define DEFAULT_SCREEN_WIDTH 1024
-#define DEFAULT_SCREEN_HEIGHT 768
+#define DEFAULT_SCREEN_WIDTH 600
+#define DEFAULT_SCREEN_HEIGHT 450
 #define BORDER_WIDTH 2
 #define DEFAULT_WINDOW_NAME "OCaml graphics"
 #define DEFAULT_SELECTED_EVENTS \
             (ExposureMask | KeyPressMask | StructureNotifyMask)
-#define DEFAULT_FONT "fixed"
+#define DEFAULT_XLFD_PATTERN "-misc-fixed-medium-r-*-*-*-%d-*-*-*-*-*-*"
 #define SIZE_QUEUE 256
 
 /* To handle events asynchronously */
@@ -81,6 +82,7 @@
 extern void caml_gr_fail(const char *fmt, const char *arg)
 CAMLnoreturn_end;
 
+extern void free_font();
 extern void caml_gr_check_open(void);
 extern unsigned long caml_gr_pixel_rgb(int rgb);
 extern int caml_gr_rgb_pixel(long unsigned int pixel);
diff -Naur graphics-master/src/unix/open.c graphics-master-utf-8/src/unix/open.c
--- graphics-master/src/unix/open.c	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/src/unix/open.c	2024-04-26 23:08:51.049988860 +0200
@@ -13,6 +13,7 @@
 /*                                                                        */
 /**************************************************************************/
 
+#include <locale.h>
 #include <string.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -38,7 +39,6 @@
 Bool caml_gr_remember_modeflag;
 int caml_gr_x, caml_gr_y;
 int caml_gr_color;
-extern XFontStruct * caml_gr_font;
 long caml_gr_selected_events;
 Bool caml_gr_ignore_sigio = False;
 static Bool caml_gr_initialized = False;
@@ -48,6 +48,7 @@
 static int caml_gr_error_handler(Display *display, XErrorEvent *error);
 static int caml_gr_ioerror_handler(Display *display);
 value caml_gr_clear_graph(void);
+value caml_gr_close_graph(void);
 
 value caml_gr_open_graph(value arg)
 {
@@ -59,6 +60,8 @@
   XEvent event;
   int x, y, w, h;
   XWindowAttributes attributes;
+  
+  setlocale(LC_CTYPE, "fr_FR.UTF-8");
 
   if (caml_gr_initialized) {
     caml_gr_clear_graph();
@@ -117,6 +120,10 @@
       XCreateSimpleWindow(caml_gr_display, DefaultRootWindow(caml_gr_display),
                           hints.x, hints.y, hints.width, hints.height,
                           BORDER_WIDTH, caml_gr_black, caml_gr_background);
+    /* register interest in the delete window message */
+    caml_wm_delete_window = XInternAtom(caml_gr_display, "WM_DELETE_WINDOW", False);
+    XSetWMProtocols(caml_gr_display, caml_gr_window.win, &caml_wm_delete_window, 1);
+
     p = window_name;
     if (p == NULL) p = DEFAULT_WINDOW_NAME;
     /* What not use XSetWMProperties? */
@@ -223,16 +230,16 @@
     setitimer(ITIMER_REAL, &it, NULL);
 #endif
     caml_gr_initialized = False;
-    if (caml_gr_font != NULL) {
-      XFreeFont(caml_gr_display, caml_gr_font); caml_gr_font = NULL;
-    }
     XFreeGC(caml_gr_display, caml_gr_window.gc);
     XDestroyWindow(caml_gr_display, caml_gr_window.win);
     XFreeGC(caml_gr_display, caml_gr_bstore.gc);
     XFreePixmap(caml_gr_display, caml_gr_bstore.win);
     XFlush(caml_gr_display);
-    XCloseDisplay (caml_gr_display);
-    caml_gr_display = NULL;
+    window_name = NULL;
+    if (font_set != NULL) {
+      free_font();
+      font_set = NULL;
+    }
   }
   return Val_unit;
 }
@@ -251,12 +258,23 @@
   return caml_gr_id_of_window(caml_gr_window.win);
 }
 
+// les deux fonctions suivantes sont définies dans text.c
+extern int is_utf8(const unsigned char* s);
+extern void to_utf8(const unsigned char* txt, char* st);
+
 value caml_gr_set_window_title(value n)
 {
   if (window_name != NULL) caml_stat_free(window_name);
-  window_name = caml_stat_strdup(String_val(n));
+  const unsigned char* t = String_val(n);
+  if (is_utf8(t)) {
+    window_name = caml_stat_strdup(t);
+  }
+  else {
+    window_name = caml_stat_alloc(2*strlen(t)+1);
+    to_utf8(t,window_name);
+  }
   if (caml_gr_initialized) {
-    XStoreName(caml_gr_display, caml_gr_window.win, window_name);
+    XChangeProperty(caml_gr_display, caml_gr_window.win, XInternAtom(caml_gr_display, "_NET_WM_NAME", False), XInternAtom(caml_gr_display, "UTF8_STRING", False), 8, 0, (unsigned char*)window_name, strlen(window_name));
     XSetIconName(caml_gr_display, caml_gr_window.win, window_name);
     XFlush(caml_gr_display);
   }
@@ -374,8 +392,9 @@
 /* Processing of graphic errors */
 
 static const value * graphic_failure_exn = NULL;
-
+// static value * graphic_failure_exn = NULL;
 void caml_gr_fail(const char *fmt, const char *arg)
+// void caml_gr_fail(char *fmt, char *arg)
 {
   char buffer[1024];
 
diff -Naur graphics-master/src/unix/text.c graphics-master-utf-8/src/unix/text.c
--- graphics-master/src/unix/text.c	2023-01-05 14:35:00.000000000 +0100
+++ graphics-master-utf-8/src/unix/text.c	2024-04-26 22:49:29.632431221 +0200
@@ -13,74 +13,216 @@
 /*                                                                        */
 /**************************************************************************/
 
+#include <locale.h>
 #include "libgraph.h"
 #include <caml/alloc.h>
+#include <string.h>
+#include <caml/fail.h>
 
-XFontStruct * caml_gr_font = NULL;
-
-static void caml_gr_get_font(const char *fontname)
-{
-  XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname);
-  if (font == NULL) caml_gr_fail("cannot find font %s", fontname);
-  if (caml_gr_font != NULL) XFreeFont(caml_gr_display, caml_gr_font);
-  caml_gr_font = font;
-  XSetFont(caml_gr_display, caml_gr_window.gc, caml_gr_font->fid);
-  XSetFont(caml_gr_display, caml_gr_bstore.gc, caml_gr_font->fid);
+#define MAXLENGTH 255
+static int text_size = 120;
+static char current_xlfd_pattern[MAXLENGTH + 1] = DEFAULT_XLFD_PATTERN;
+XFontSet font_set = NULL;
+
+static size_t text_length(const char * str)
+{
+    setlocale(LC_CTYPE, "fr_FR.UTF-8");
+    size_t lenW = mbstowcs( NULL, str, 0);
+    return lenW;
+}
+
+value caml_gr_text_length(value str)
+{
+    size_t i = text_length(String_val(str));
+    if (i == (size_t)-1) {caml_invalid_argument("text_length"); return Val_unit;}
+    return Val_int((int)i);
+}
+
+static void create_font_set(const char* xlfd_pattern)
+{
+    setlocale(LC_CTYPE, "fr_FR.UTF-8");
+    char **missing_charset_list;
+    int missing_charset_count;
+    char *def_string;
+    char str[MAXLENGTH + 1];
+    sprintf(str, xlfd_pattern, text_size);
+    font_set = XCreateFontSet(caml_gr_display, str, &missing_charset_list, &missing_charset_count, &def_string);
+    if (font_set == NULL) caml_invalid_argument("font set creation failure");
+}
+
+static int check_font_name(const char* name)
+{
+    int i = 0;
+    char* p = (char*)name;
+    if (*p == '-') return -1;
+    char* q = (char*)name;
+    while (*p) {
+        if (*p == '-'){
+            ++i;
+            ++p;
+            q = p;
+            if (i > 1) return -2;
+        }
+        else ++p;
+    }
+    if (*q == 0) return -3;
+    return q - name;
 }
 
 value caml_gr_set_font(value fontname)
 {
-  caml_gr_check_open();
-  caml_gr_get_font(String_val(fontname));
-  return Val_unit;
+    const char* fntName = String_val(fontname);
+    int l = strlen(fntName) + strlen("-medium-r-*-*-*-%d-*-*-*-*-*-*");
+    int i = check_font_name(fntName);
+    char str[MAXLENGTH + 1];
+    if (i == 0){
+        if (l + 3 > MAXLENGTH) caml_invalid_argument("font name too long");
+        strcpy(str, "-*-");
+        strcat(str, fntName);
+    }
+    else if (i > 0){
+        if (l + 1 > MAXLENGTH) caml_invalid_argument("font name too long");
+        strcpy(str, "-");
+        strcat(str, fntName);
+    }
+    else caml_invalid_argument("font name here must have at most one '-' and no leading or trailing '-'");
+    strcat(str, "-medium-r-*-*-*-%d-*-*-*-*-*-*");
+    create_font_set(str);
+    strcpy(current_xlfd_pattern, str);
+    return Val_unit;
+}
+
+void free_font()
+{
+    if (font_set) {
+        XFreeFontSet(caml_gr_display, font_set);
+        font_set = NULL;
+    }
 }
 
 value caml_gr_set_text_size (value sz)
 {
-  return Val_unit;
-}
-
-static void caml_gr_draw_text(const char *txt, int len)
-{
-  if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
-  if (caml_gr_remember_modeflag)
-    XDrawString(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
-                caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1, txt,
-                len);
-  if (caml_gr_display_modeflag) {
-    XDrawString(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
-                caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1, txt,
-                len);
-    XFlush(caml_gr_display);
-  }
-  caml_gr_x += XTextWidth(caml_gr_font, txt, len);
+    int size = 10 * Int_val(sz);
+    if (text_size != size)
+    {
+        text_size = size;
+        free_font();
+        create_font_set(current_xlfd_pattern);
+    }
+    return Val_unit;
+}
+
+static int num(unsigned char c)
+{
+    if (c >> 7 == 0) return 0;
+    if (c >> 6 == 2) return -1;
+    if (c >> 5 == 6) return 1;
+    if (c >> 4 == 14) return 2;
+    if (c >> 3 == 30) return 3;
+    return 4;
+}
+
+// test de conformité à UTF-8 d'une chaîne s
+int is_utf8(const unsigned char* s)
+{
+    int m = 0;
+    for (unsigned char* t = (unsigned char*)s; *t != '\0'; t++)
+    {
+        int n = num(*t);
+        if (n == 4) return 0;
+        if (m > 0)
+        {
+            if (n == -1) m--; else return 0;
+        }
+        else
+        {
+            m = n;
+        }
+    }
+    return (m == 0);
+}
+// conversion d'une chaîne txt d'octets censés représenter des caractères latin1 en chaîne UTF-8
+// chaque caractères UTF-8 occupent ici 1 ou 2 octets selon qu'il encode un octet < 128 ou non
+// la chaîne d'octets convertie est au plus deux fois plus longue que la chaîne inintiale
+void to_utf8(const unsigned char* txt, unsigned char* st)
+{
+    unsigned char* out = st;
+    for(const unsigned char* in = txt; *in != 0; in++) {
+        if (*in < 128) *out++ = *in;
+        else {
+            *out++ = (0xC0 | (*in >> 6));
+            *out++ = (0x80 | (*in & 0x3F));
+        }
+    }
+    *out = 0;;
+}
+
+static void caml_gr_draw_text_utf8(const unsigned char * txt, int len)
+//Si la chaîne txt n'est pas conforme à UTF-8 on la convertit
+{
+    unsigned char* st;
+    int b = !is_utf8(txt);
+    if (b)
+    {
+        st = (unsigned char*)malloc(2*strlen(txt)+1);
+        if (st) to_utf8(txt, st);
+        len = strlen(st);
+    }
+    else st = (unsigned char*)txt;
+    if (font_set == NULL) create_font_set(current_xlfd_pattern);
+    if (font_set) {
+        setlocale(LC_CTYPE, "fr_FR.UTF-8");
+        if (caml_gr_remember_modeflag) {
+            Xutf8DrawString(caml_gr_display, caml_gr_bstore.win, font_set, caml_gr_bstore.gc,
+                            caml_gr_x, Bcvt(caml_gr_y), st, len);
+        }
+        XFlush(caml_gr_display);
+        if (caml_gr_display_modeflag) {
+            Xutf8DrawString(caml_gr_display, caml_gr_window.win, font_set, caml_gr_window.gc,
+                            caml_gr_x, Wcvt(caml_gr_y), st, len);
+            XFlush(caml_gr_display);
+        }
+        caml_gr_x += Xutf8TextEscapement(font_set, st, len);
+    }
+    if (b && st) free(st);
 }
 
 value caml_gr_draw_char(value chr)
 {
-  char str[1];
-  caml_gr_check_open();
-  str[0] = Int_val(chr);
-  caml_gr_draw_text(str, 1);
-  return Val_unit;
+    unsigned char i =  Int_val(chr);
+    wchar_t str[2];
+    str[0] = i;
+    str[1] = 0;
+    char str1[3] ;
+    setlocale(LC_CTYPE, "fr_FR.UTF-8");
+    int n = wcstombs(str1, str, 2);
+    if (n == (size_t)-1) {caml_invalid_argument("draw_char"); return Val_unit;}
+    str1[n]='\0';
+    caml_gr_draw_text_utf8(str1, n);
+    return Val_unit;
 }
 
 value caml_gr_draw_string(value str)
 {
-  caml_gr_check_open();
-  caml_gr_draw_text(String_val(str), caml_string_length(str));
-  return Val_unit;
+    caml_gr_check_open();
+    caml_gr_draw_text_utf8(String_val(str), caml_string_length(str));
+    return Val_unit;
 }
 
 value caml_gr_text_size(value str)
 {
-  int width;
-  value res;
-  caml_gr_check_open();
-  if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
-  width = XTextWidth(caml_gr_font, String_val(str), caml_string_length(str));
-  res = caml_alloc_small(2, 0);
-  Field(res, 0) = Val_int(width);
-  Field(res, 1) = Val_int(caml_gr_font->ascent + caml_gr_font->descent);
-  return res;
+    int width;
+    value res;
+    caml_gr_check_open();
+    const unsigned char *s = String_val(str);
+    char* st = (char*)s;
+    int b = !is_utf8(s);
+    if (b) {st = (char*)malloc(2*strlen(s)+1);if (st) to_utf8(s,st);}
+    if (font_set == NULL) create_font_set(current_xlfd_pattern);
+    width = Xutf8TextEscapement(font_set, st, strlen(st));
+    if (b && st != (char*)s) free(st);
+    res = caml_alloc_small(2, 0);
+    Field(res, 0) = Val_int(width);
+    Field(res, 1) = Val_int(text_size / 10);
+    return res;
 }
