From 888b586dd86034a20e51bc3fb15701cd870402bc Mon Sep 17 00:00:00 2001
From: juanitotc <john.frankish@outlook.com>
Date: Wed, 12 Mar 2025 14:18:49 +0000
Subject: [PATCH] juanito: rotated text and border fixes from fltk folks

---
 Frame.C   | 11 +++++++++++
 Rotated.C | 28 +++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/Frame.C b/Frame.C
index a52d314..7c46a5d 100644
--- a/Frame.C
+++ b/Frame.C
@@ -17,6 +17,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <FL/fl_draw.H>
+#if FL_API_VERSION >= 10400
+#  if FLTK_USE_CAIRO
+  #include <cairo/cairo-xlib.h>
+#  endif
+#endif
 
 #ifndef HAVE_XFT
 #include "Rotated.H" // text rotation code; not supported by non-Xft FLTK 1.3.x
@@ -1116,6 +1121,12 @@ void Frame::set_size(int nx, int ny, int nw, int nh, int warp) {
   // for configure request, move the cursor first
   if (warp == 2 && active() && !Fl::pushed()) warp_pointer();
   XMoveResizeWindow(fl_display, fl_xid(this), nx, ny, nw, nh);
+#if FL_API_VERSION >= 10400
+#  if FLTK_USE_CAIRO
+  make_current();
+  if (fl_cairo_gc()) cairo_xlib_surface_set_size(cairo_get_target(fl_cairo_gc()), nw, nh);
+#  endif
+#endif
   if (nw <= dwidth) {
     if (unmap) {
       set_state_flag(IGNORE_UNMAP);
diff --git a/Rotated.C b/Rotated.C
index dfeb02d..b4f1d83 100644
--- a/Rotated.C
+++ b/Rotated.C
@@ -36,6 +36,17 @@
 #include <string.h>
 #include <stdio.h>
 
+// If the FLTK version is 1.3.0 or higher FLTK's native rotated
+// text drawing can be used rather than "doing it manually"
+
+#if defined(FL_API_VERSION) && (FL_API_VERSION >= 10300)
+#define FLTK_ROTATED_TEXT 1
+#else
+#define FLTK_ROTATED_TEXT 0
+#endif
+
+#if (!FLTK_ROTATED_TEXT)
+
 struct BitmapStruct {
   int			 bit_w;
   int			 bit_h;
@@ -328,6 +339,9 @@ XRotDrawString(Display *dpy, XRotFontStruct *rotfont, Drawable drawable,
   XSetFillStyle(dpy, gc, FillSolid);
 }
 
+#endif // (!FLTK_ROTATED_TEXT)
+
+
 #ifndef FLWM
 /* *** Return the width of a string *** */
 
@@ -353,6 +367,8 @@ static int XRotTextWidth(XRotFontStruct *rotfont, const char *str, int len)
 
 // the public functions use the fltk global variables for font & gc:
 
+#if (!FLTK_ROTATED_TEXT)
+
 static XRotFontStruct* font;
 
 static void setrotfont(int angle) {
@@ -373,7 +389,17 @@ void draw_rotated(const char* text, int n, int x, int y, int angle) {
   XRotDrawString(fl_display, font, fl_window, fl_gc, x, y, text, n);
 }
 
-#if !defined(FLWM) || FL_MAJOR_VERSION>=2
+#endif // (!FLTK_ROTATED_TEXT)
+
+#if (FLTK_ROTATED_TEXT)
+
+void draw_rotated(const char* text, int x, int y, int angle) {
+  if (!text || !*text) return;
+  fl_draw(angle, text, strlen(text), x, y);
+}
+
+#elif !defined(FLWM) || FL_MAJOR_VERSION>=2
+
 void draw_rotated(const char* text, int x, int y, int angle) {
   if (!text || !*text) return;
   draw_rotated(text, strlen(text), x, y, angle);
