Repository: mozilla/pdf.js
File: src/core/annotation.js (JavaScript)

Code before:
        );
      }
    }
  }

  get hasTextContent() {
    return this._hasAppearance;
  }

  static createNewDict(annotation, xref, { apRef, ap }) {
    const {
      color,
      date,
      fontSize,
      oldAnnotation,
      rect,
      rotation,
      user,
      value,
    } = annotation;
    const pdfDate = `D:${getModificationDate(date)}`;
    const freetext = oldAnnotation || new Dict(xref);
    freetext.setIfNotExists("Type", Name.get("Annot"));
    freetext.setIfNotExists("Subtype", Name.get("FreeText"));
    if (oldAnnotation) {
      freetext.set("M", pdfDate);
      // TODO: We should try to generate a new RC from the content we've.
      // For now we can just remove it to avoid any issues.
      freetext.delete("RC");
    } else {
      freetext.set("CreationDate", pdfDate);
    }
    freetext.setIfArray("Rect", rect);
    const da = `/Helv ${fontSize} Tf ${getPdfColor(color, /* isFill */ true)}`;
    freetext.set("DA", da);
    freetext.setIfDefined("Contents", stringToAsciiOrUTF16BE(value));
    freetext.setIfNotExists("F", 4);
    freetext.setIfNotExists("Border", [0, 0, 0]);
    freetext.setIfNumber("Rotate", rotation);
    freetext.setIfDefined("T", stringToAsciiOrUTF16BE(user));

    if (apRef || ap) {
      const n = new Dict(xref);
      freetext.set("AP", n);
      n.set("N", apRef || ap);
    }

    return freetext;
  }

  static async createNewAppearanceStream(annotation, xref, params) {

Review comment (suggestion):
Let's use the same structure as for the annotation types changed below for consistency:

```
freetext.set(
  oldAnnotation ? "M" : "CreationDate",
  `D:${getModificationDate(date)}`
);
```

This keeps the `getModificationDate` call in a single place so we also don't need the separate `pdfDate` variable.

Code after:
        );
      }
    }
  }

  get hasTextContent() {
    return this._hasAppearance;
  }

  static createNewDict(annotation, xref, { apRef, ap }) {
    const {
      color,
      date,
      fontSize,
      oldAnnotation,
      rect,
      rotation,
      user,
      value,
    } = annotation;
    const freetext = oldAnnotation || new Dict(xref);
    freetext.setIfNotExists("Type", Name.get("Annot"));
    freetext.setIfNotExists("Subtype", Name.get("FreeText"));
    freetext.set(
      oldAnnotation ? "M" : "CreationDate",
      `D:${getModificationDate(date)}`
    );
    if (oldAnnotation) {
      // TODO: We should try to generate a new RC from the content we've.
      // For now we can just remove it to avoid any issues.
      freetext.delete("RC");
    }
    freetext.setIfArray("Rect", rect);
    const da = `/Helv ${fontSize} Tf ${getPdfColor(color, /* isFill */ true)}`;
    freetext.set("DA", da);
    freetext.setIfDefined("Contents", stringToAsciiOrUTF16BE(value));
    freetext.setIfNotExists("F", 4);
    freetext.setIfNotExists("Border", [0, 0, 0]);
    freetext.setIfNumber("Rotate", rotation);
    freetext.setIfDefined("T", stringToAsciiOrUTF16BE(user));

    if (apRef || ap) {
      const n = new Dict(xref);
      freetext.set("AP", n);
      n.set("N", apRef || ap);
    }

    return freetext;
  }

  static async createNewAppearanceStream(annotation, xref, params) {