Esempio n. 1
0
 /**
  * Ajoute les commandes <code>
  * \\definecolor{colourName}{rgb}{<var>r</var>,<var>g</var>,<var>b</var>}
  * </code> au tampon <code>buf</code> passé en argument.
  *
  * @since jPicEdt 1.6
  */
 public static void addUserDefinedColourDefinitions(
     StringBuffer buf, ParameterString p, TikzFormatter factory) {
   float[] colourComponents = new float[3];
   for (ParameterString.UserDefinedColour c : p.getUserDefinedColourList()) {
     buf.append("\\definecolor{");
     buf.append(c.name);
     buf.append("}{rgb}{");
     colourComponents = c.colour.getRGBColorComponents(colourComponents);
     buf.append(PEToolKit.doubleToString(colourComponents[0]));
     buf.append(",");
     buf.append(PEToolKit.doubleToString(colourComponents[1]));
     buf.append(",");
     buf.append(PEToolKit.doubleToString(colourComponents[2]));
     buf.append("}");
     buf.append(factory.getLineSeparator());
   }
 }
Esempio n. 2
0
  /** @return la liste de paramètres standard de TikZ pour l'objet élément passé en argument. */
  public static ParameterString createParameterString(
      Element obj,
      PicAttributeSet defaultAttributes,
      TikzCustomProperties tikzCustomProperties,
      BitSet mask) {

    ColorFormatter.ColorEncoding predefinedColorSet =
        tikzCustomProperties.getFormatterPredefinedColorSet();
    PicAttributeSet attributes = obj.getAttributeSet();

    StringBuffer paramBuf = new StringBuffer(100);
    ParameterString parameterString = new ParameterString(paramBuf, null);
    // no user-defined colour by default --------------------------^

    // linewidth
    double lineWidth = attributes.getAttribute(LINE_WIDTH);
    if (lineWidth != defaultAttributes.getAttribute(LINE_WIDTH)) {
      paramBuf.append("line width=");
      paramBuf.append(PEToolKit.doubleToString(lineWidth));
      paramBuf.append("mm");
    }

    // linecolor
    Color lineColor = attributes.getAttribute(LINE_COLOR);
    if (!lineColor.equals(defaultAttributes.getAttribute(LINE_COLOR))) {
      if (paramBuf.length() > 0) paramBuf.append(',');
      paramBuf.append("color=");
      String lineColorName = ColorFormatter.format(lineColor, predefinedColorSet);
      if (lineColorName != null) paramBuf.append(lineColorName); // ok, this is a predefined colour
      else { // define a new colour named "userLineColor" (it doesn't matter if it's not a unique
             // name, provided the caller insert it just BEFORE the command that needs it)
        parameterString.addUserDefinedColour("userLineColour", lineColor);
        paramBuf.append("userLineColour");
      }
    }

    // linestyle
    switch (attributes.getAttribute(LINE_STYLE)) {
      case DASHED:
        if (paramBuf.length() > 0) paramBuf.append(',');
        paramBuf.append("dash pattern= on ");
        paramBuf.append(PEToolKit.doubleToString(attributes.getAttribute(DASH_OPAQUE)));
        paramBuf.append("mm off ");
        paramBuf.append(PEToolKit.doubleToString(attributes.getAttribute(DASH_TRANSPARENT)));
        paramBuf.append("mm");
        break;
      case DOTTED:
        {
          double dotSep = attributes.getAttribute(DOT_SEP);
          if (dotSep > lineWidth) {
            if (paramBuf.length() > 0) paramBuf.append(',');
            paramBuf.append("dash pattern=on \\pgflinewidth off ");
            paramBuf.append(PEToolKit.doubleToString(dotSep - lineWidth));
            paramBuf.append("mm");
          }
        }
        break;
      case SOLID:
        break;
      case NONE:
        parameterString.setDrawToNone();
        break;
      default:
        debug("Unexpected LINE_STYLE");
    }

    // overstrike (if border > 0)
    // if (attributes.getAttribute(OVER_STRIKE)==Boolean.TRUE){
    // 	if (paramBuf.length()>0) paramBuf.append(',');
    // 	paramBuf.append("border=");
    // 	paramBuf.append(PEToolKit.doubleToString(attributes.getAttribute(OVER_STRIKE_WIDTH)));
    // }

    // fill style and fill colour
    FillStyle fillStyle = attributes.getAttribute(FILL_STYLE);
    if (fillStyle == FillStyle.NONE) {
    } else { // solid or hatches -> add fill colour (even if it's redundant for hatches that are not
             // "starred"=
      Color fillColor = attributes.getAttribute(FILL_COLOR);
      if (!(fillColor.equals(defaultAttributes.getAttribute(FILL_COLOR)))) { // i.e. "black" so far
        String fillColorName =
            ColorFormatter.format(fillColor, tikzCustomProperties.getFormatterPredefinedColorSet());
        if (paramBuf.length() > 0) paramBuf.append(',');
        paramBuf.append("fill=");
        if (fillColorName != null)
          paramBuf.append(fillColorName); // ok, this is a predefined colour
        else { // define a new colour named "userFillColor" (it doesn't matter if it's not a unique
               // name, provided the caller insert it just BEFORE the command that needs it)
          parameterString.addUserDefinedColour("userFillColour", fillColor);
          paramBuf.append("userFillColour");
        }
      } else parameterString.setFill();

      if (fillStyle == FillStyle.SOLID) {
      } else { // hatches
        // if (paramBuf.length()>0) paramBuf.append(',');
        // switch (fillStyle){
        // case VLINES: paramBuf.append("fillstyle=vlines"); break;
        // case VLINES_FILLED: paramBuf.append("fillstyle=vlines*"); break;
        // case HLINES: paramBuf.append("fillstyle=hlines"); break;
        // case HLINES_FILLED: paramBuf.append("fillstyle=hlines*"); break;
        // case CROSSHATCH: paramBuf.append("fillstyle=crosshatch"); break;
        // case CROSSHATCH_FILLED: paramBuf.append("fillstyle=crosshatch*"); break;
        // default://else throw new RuntimeException("not supported: fillstyle="+fillStyle);
        // }

        // double x = attributes.getAttribute(HATCH_WIDTH);
        // if (x!=defaultAttributes.getAttribute(HATCH_WIDTH)){
        // 	paramBuf.append(",hatchwidth=");
        // 	paramBuf.append(PEToolKit.doubleToString(x));
        // }
        // x = attributes.getAttribute(HATCH_SEP);
        // if (x!=defaultAttributes.getAttribute(HATCH_SEP)){
        // 	paramBuf.append(",hatchsep=");
        // 	paramBuf.append(PEToolKit.doubleToString(x));
        // }
        // x = attributes.getAttribute(HATCH_ANGLE);
        // if (x!=defaultAttributes.getAttribute(HATCH_ANGLE)){
        // 	paramBuf.append(",hatchangle=");
        // 	paramBuf.append(PEToolKit.doubleToString(x));
        // }

        // Color hatchColor = attributes.getAttribute(HATCH_COLOR);
        // if (!(hatchColor.equals(defaultAttributes.getAttribute(HATCH_COLOR)))){
        // 	paramBuf.append(",hatchcolor=");
        // 	String hatchColorName = TikzUtilities.getColorName(hatchColor);
        // 	if (hatchColorName != null) paramBuf.append(hatchColorName); // ok, this is a predefined
        // colour
        // 	else { // define a new colour named "userHatchColor" (it doesn't matter if it's not a
        // unique name, provided the caller insert it just BEFORE the command that needs it)
        // 		userDefinedColourList =
        // addUserDefinedColour(userDefinedColourList,"userHatchColour",hatchColor);
        // 		paramBuf.append("userHatchColour");
        // 	}
        // }
      }
    }
    // shadow
    if (attributes.getAttribute(SHADOW) == Boolean.TRUE) {
      if (paramBuf.length() > 0) paramBuf.append(',');
      paramBuf.append("shadow={");
      int argCount = 0;
      double r = attributes.getAttribute(SHADOW_SIZE);
      double a = attributes.getAttribute(SHADOW_ANGLE);
      if (r != defaultAttributes.getAttribute(SHADOW_SIZE)
          && a != defaultAttributes.getAttribute(SHADOW_ANGLE)) {
        ++argCount;
        a = toRadians(a);
        paramBuf.append("shadow xshift=");
        paramBuf.append(PEToolKit.doubleToString(r * cos(a)));
        paramBuf.append("mm ,shadow yshift=");
        paramBuf.append(PEToolKit.doubleToString(r * sin(a)));
        paramBuf.append("mm");
      }
      Color shadowColor = attributes.getAttribute(SHADOW_COLOR);
      if (!(shadowColor.equals(defaultAttributes.getAttribute(SHADOW_COLOR)))) {
        if (argCount != 0) paramBuf.append(',');
        ++argCount;

        paramBuf.append("fille=");
        String shadowColorName = ColorFormatter.format(shadowColor, predefinedColorSet);
        if (shadowColorName != null)
          paramBuf.append(shadowColorName); // ok, this is a predefined colour
        else { // define a new colour named "userShadowColor"
          parameterString.addUserDefinedColour("userShadowColour", shadowColor);
          paramBuf.append("userShadowColour");
        }
      }
      paramBuf.append('}');
    }

    // arrow parameters if at least one arrow is present
    if (attributes.getAttribute(LEFT_ARROW) != ArrowStyle.NONE
        || attributes.getAttribute(RIGHT_ARROW) != ArrowStyle.NONE) {
      // Tikz Arrow styles
      if (paramBuf.length() > 0) paramBuf.append(',');
      paramBuf.append(
          createArrowStringFromArrows(
              attributes,
              tikzCustomProperties,
              mask.get(TikzConstants.DrawFlags.SWAP_ARROWS.getValue())));

      // 	double x,y;
      // 	x = attributes.getAttribute(ARROW_GLOBAL_SCALE_LENGTH);
      // 	y = attributes.getAttribute(ARROW_GLOBAL_SCALE_WIDTH);
      // 	if (x!=defaultAttributes.getAttribute(ARROW_GLOBAL_SCALE_LENGTH) ||
      // y!=defaultAttributes.getAttribute(ARROW_GLOBAL_SCALE_WIDTH)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("arrowscale=");
      // 		paramBuf.append(PEToolKit.doubleToString(y));
      // 		paramBuf.append(' ');
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 	}
      // 	x = attributes.getAttribute(ARROW_WIDTH_MINIMUM_MM);
      // 	y = attributes.getAttribute(ARROW_WIDTH_LINEWIDTH_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(ARROW_WIDTH_MINIMUM_MM) ||
      // y!=defaultAttributes.getAttribute(ARROW_WIDTH_LINEWIDTH_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("arrowsize=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 		paramBuf.append(' ');
      // 		paramBuf.append(PEToolKit.doubleToString(y));
      // 	}
      // 	x = attributes.getAttribute(ARROW_LENGTH_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(ARROW_LENGTH_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("arrowlength=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 	}
      // 	x = attributes.getAttribute(ARROW_INSET_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(ARROW_INSET_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("arrowinset=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 	}
      // 	x = attributes.getAttribute(TBAR_WIDTH_MINIMUM_MM);
      // 	y = attributes.getAttribute(TBAR_WIDTH_LINEWIDTH_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(TBAR_WIDTH_MINIMUM_MM) ||
      // y!=defaultAttributes.getAttribute(TBAR_WIDTH_LINEWIDTH_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("tbarsize=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 		paramBuf.append(' ');
      // 		paramBuf.append(PEToolKit.doubleToString(y));
      // 	}
      // 	x = attributes.getAttribute(BRACKET_LENGTH_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(BRACKET_LENGTH_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("bracketlength=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 	}
      // 	x = attributes.getAttribute(RBRACKET_LENGTH_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(RBRACKET_LENGTH_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("rbracketlength=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 	}
      // 	// [pending] check if not already set by polydots
      // 	x = attributes.getAttribute(POLYDOTS_SIZE_MINIMUM_MM);
      // 	y = attributes.getAttribute(POLYDOTS_SIZE_LINEWIDTH_SCALE);
      // 	if (x!=defaultAttributes.getAttribute(POLYDOTS_SIZE_MINIMUM_MM) ||
      // y!=defaultAttributes.getAttribute(POLYDOTS_SIZE_LINEWIDTH_SCALE)){
      // 		if (paramBuf.length()>0) paramBuf.append(',');
      // 		paramBuf.append("dotsize=");
      // 		paramBuf.append(PEToolKit.doubleToString(x));
      // 		paramBuf.append(' ');
      // 		paramBuf.append(PEToolKit.doubleToString(y));
      // 	}
    }

    // double line
    // if (attributes.getAttribute(DOUBLE_LINE)==Boolean.TRUE){
    // 	if (paramBuf.length()>0) paramBuf.append(',');
    // 	paramBuf.append("double=");
    // 	double x = attributes.getAttribute(DOUBLE_SEP);
    // 	if (x!=defaultAttributes.getAttribute(DOUBLE_SEP)){
    // 		paramBuf.append(",doublesep=");
    // 		paramBuf.append(PEToolKit.doubleToString(x));
    // 	}
    // 	Color doubleColor =  attributes.getAttribute(DOUBLE_COLOR);
    // 	if (!(doubleColor.equals(defaultAttributes.getAttribute(DOUBLE_COLOR)))){
    // 		paramBuf.append(",doublecolor=");
    // 		String doubleColorName = TikzUtilities.getColorName(doubleColor);
    // 		if (doubleColorName != null) paramBuf.append(doubleColorName); // ok, this is a predefined
    // colour
    // 		else { // define a new colour named "userDoubleColor"
    // 			userDefinedColourList =
    // addUserDefinedColour(userDefinedColourList,"userDoubleColour",doubleColor);
    // 			paramBuf.append("userDoubleColour");
    // 		}
    // 	}
    // }

    // misc params
    // switch (attributes.getAttribute(DIMEN)){
    // case INNER:
    // 	if (paramBuf.length()>0) paramBuf.append(',');
    // 	paramBuf.append("dimen=inner");
    // 	break;
    // case MIDDLE:
    // 	if (paramBuf.length()>0) paramBuf.append(',');
    // 	paramBuf.append("dimen=middle");
    // 	break;
    // default:// else default="outer"
    // }

    // Custom TikZ parameters.
    {
      String customs = attributes.getAttribute(TIKZ_CUSTOM);
      if (customs.length() > 0) {
        if (paramBuf.length() > 0) paramBuf.append(',');
        paramBuf.append(customs);
      }
    }

    return parameterString;
  }