public override void Draw(DocumentWriter writer) { const int shadingPatternType = 2; // tiling pattern = 1 void WriteNumberHighPrecision(float v) { // WriteNumber isn't high precision enough, only supports 2 decimal places :( var bytes = Encoding.ASCII.GetBytes($"{v} "); writer.Write(bytes); } writer.WriteBeginObject(); writer.WriteDictionaryOpen(); { writer.WriteName(NamePatternTypeBytes); writer.WriteNumber(shadingPatternType); writer.WriteName(NameMatrixBytes); writer.WriteArrayOpen(); { _shadingColor.DrawMatrix(WriteNumberHighPrecision); } writer.WriteArrayClose(); writer.WriteName(NameShadingBytes); writer.WriteDictionaryOpen(); { writer.WriteName(NameShadingTypeBytes); writer.WriteNumber((int)_shadingColor.ShadingType); writer.WriteName(NameColorSpaceBytes); _shadingColor.Stops[0].Color.ColorSpace.DrawColorSpace(writer); writer.WriteName(NameCoordsBytes); writer.WriteArrayOpen(); { _shadingColor.DrawCoordinates(WriteNumberHighPrecision); } writer.WriteArrayClose(); writer.WriteName(NameExtendBytes); writer.WriteArrayOpen(); { writer.WriteBoolean(true); writer.WriteBoolean(true); } writer.WriteArrayClose(); writer.WriteName(NameFunctionBytes); if (_shadingColor.Stops.Count > 2) { WriteStitchingFunction(writer); } else if (_shadingColor.Stops.Count == 2) { var stop1 = _shadingColor.Stops[0]; var stop2 = _shadingColor.Stops[1]; WriteLinearColorInterpolationFunction(writer, stop1.Color, stop2.Color); } else { throw new InvalidOperationException($"Expected two or more color stops"); } } writer.WriteDictionaryClose(); } writer.WriteDictionaryClose(); writer.WriteEndObject(); }