code: private int stringWidth(FontMetrics fm, String text)
      {
          int w = fm.stringWidth(text);
          if (wordSpacing != null)
          {
              //count spaces and add
              float add = 0.0f;
              for (int i = 0; i < text.length(); i++)
              {
                  if (text.charAt(i) == ' ')
                      add += wordSpacing;
              }
              w = Math.round(w + add);
          }
          return w;
      }
docs: Computes the final width of a string while considering word-spacing
  @param fm the font metrics used for calculation
  @param text the string to be measured
  @return the resulting width in pixels