+ double sx = 1f * charWidth / fm.charsWidth(dc, 0, dc.length);
+ double sy = newHeight / asc;
+ double newAsc = asc * sy;
+ double newDec = dec * sy;
+ // it is not necessary to recalculate lm for the new font.
+ // note: lm.getBaselineOffsets()[lm.getBaselineIndex()]) must be 0
+ // by definition. Was:
+ // int hght = (int) (ht + (newAsc - newDec);
+ // - lm.getBaselineOffsets()[lm.getBaselineIndex()]));
+
+ if (Platform.isJS())
+ {
+ /*
+ * SwingJS does not implement font.deriveFont()
+ * so use a scaling transform to draw instead,
+ * this is off by a very small amount
+ */
+ final int hght = (int) (ht2 + (newAsc - newDec));
+ Graphics2D gg = (Graphics2D) g;
+ int xShift = (int) Math.round(x * charWidth / sx);
+ int yShift = (int) Math.round(hght / sy);
+ gg.transform(AffineTransform.getScaleInstance(sx, sy));
+ gg.drawString(s, xShift, yShift);
+ gg.transform(
+ AffineTransform.getScaleInstance(1D / sx, 1D / sy));
+ ht2 += newHeight;
+ }
+ else
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+ // Java ('normal') method is to scale the font to fit
+
+ final int hght = (int) (ht + (newAsc - newDec));
+ Font font = ofont
+ .deriveFont(AffineTransform.getScaleInstance(sx, sy));
+ g.setFont(font);
+ g.drawChars(dc, 0, dc.length, x * charWidth, hght);
+ ht += newHeight;
+ }