+/* The XGlyphInfo field names and values are, of course, arbitrarily
+ different from XCharStruct for no sensible reason. These macros
+ translate between them.
+ */
+
+# define XGlyphInfo_to_XCharStruct(G,C) do { \
+ (C).lbearing = -(G).x; \
+ (C).rbearing = (G).width - (G).x; \
+ (C).ascent = (G).y; \
+ (C).descent = (G).height - (G).y; \
+ (C).width = (G).xOff; \
+} while (0)
+
+# define XCharStruct_to_XGlyphInfo(C,G) do { \
+ (G).x = -(C).lbearing; \
+ (G).y = (C).ascent; \
+ (G).xOff = (C).width; \
+ (G).yOff = 0; \
+ (G).width = (C).rbearing - (C).lbearing; \
+ (G).height = (C).ascent + (C).descent; \
+} while (0)
+
+/* Xutf8TextExtents returns a bounding box in an XRectangle, which
+ conveniently interprets everything in the opposite direction
+ from XGlyphInfo!
+ */
+# define XCharStruct_to_XmbRectangle(C,R) do { \
+ (R).x = (C).lbearing; \
+ (R).y = -(C).ascent; \
+ (R).width = (C).rbearing - (C).lbearing; \
+ (R).height = (C).ascent + (C).descent; \
+} while (0)
+
+# define XmbRectangle_to_XCharStruct(R,C,ADV) do { \
+ (C).lbearing = (R).x; \
+ (C).rbearing = (R).width + (R).x; \
+ (C).ascent = -(R).y; \
+ (C).descent = (R).height + (R).y; \
+ (C).width = (ADV); \
+} while (0)
+
+