Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/odr/internal/font/cff_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ std::string build_index(const std::vector<std::string> &members) {
namespace odr::internal::font {

std::string cff::build_cff(const std::string_view name,
const std::vector<BuilderGlyph> &glyphs,
const std::span<const BuilderGlyph> glyphs,
const double default_width,
const double nominal_width, const FontBBox bbox) {
// CharStrings INDEX (one Type2 charstring per glyph).
Expand Down
4 changes: 2 additions & 2 deletions src/odr/internal/font/cff_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <odr/font.hpp>

#include <span>
#include <string>
#include <string_view>
#include <vector>

namespace odr::internal::font::cff {

Expand All @@ -28,7 +28,7 @@ struct BuilderGlyph {
/// default); a non-default matrix is a follow-up. Top DICT offsets use the
/// fixed-width 5-byte integer form so the layout resolves in a single pass.
[[nodiscard]] std::string build_cff(std::string_view name,
const std::vector<BuilderGlyph> &glyphs,
std::span<const BuilderGlyph> glyphs,
double default_width, double nominal_width,
FontBBox bbox);

Expand Down
10 changes: 6 additions & 4 deletions src/odr/internal/font/type1_charstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void emit_num(std::string &out, const double v) {
/// `callsubr`), emitting a Type2 charstring.
class Translator {
public:
explicit Translator(const std::vector<std::string> &subrs) : m_subrs(subrs) {}
explicit Translator(const std::span<const std::string> subrs)
: m_subrs(subrs) {}

Type2Charstring run(const std::string_view charstring) {
execute(charstring, 0);
Expand Down Expand Up @@ -411,7 +412,7 @@ class Translator {
double y;
};

const std::vector<std::string> &m_subrs;
std::span<const std::string> m_subrs;
std::string m_out;
std::vector<double> m_stack;
std::vector<double> m_ps_stack;
Expand All @@ -433,8 +434,9 @@ class Translator {

namespace odr::internal::font {

type1::Type2Charstring type1::to_type2(const std::string_view type1,
const std::vector<std::string> &subrs) {
type1::Type2Charstring
type1::to_type2(const std::string_view type1,
const std::span<const std::string> subrs) {
return Translator(subrs).run(type1);
}

Expand Down
4 changes: 2 additions & 2 deletions src/odr/internal/font/type1_charstring.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <vector>

namespace odr::internal::font::type1 {

Expand All @@ -27,6 +27,6 @@ struct Type2Charstring {
/// quality, not glyph shape), and unknown operators are skipped. Throws
/// `std::runtime_error` on a charstring that ends mid-operand.
[[nodiscard]] Type2Charstring to_type2(std::string_view type1,
const std::vector<std::string> &subrs);
std::span<const std::string> subrs);

} // namespace odr::internal::font::type1
4 changes: 2 additions & 2 deletions src/odr/internal/pdf/pdf_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::shared_ptr<ColorSpaceDef> space_from_name(const std::string &name,
} // namespace

std::array<double, 3>
ColorSpaceDef::to_rgb(const std::vector<double> &c) const {
ColorSpaceDef::to_rgb(const std::span<const double> c) const {
const auto at = [&](const std::size_t i) {
return i < c.size() ? c[i] : 0.0;
};
Expand Down Expand Up @@ -141,7 +141,7 @@ ColorSpaceDef::to_rgb(const std::vector<double> &c) const {
const double v = clamp01(1 - at(0));
return {v, v, v};
}
return alternate->to_rgb(tint->eval(c));
return alternate->to_rgb(tint->eval({c.begin(), c.end()}));
}
case ColorSpaceKind::pattern:
// An uncoloured pattern (`/PaintType 2`) carries its colour in the Pattern
Expand Down
3 changes: 2 additions & 1 deletion src/odr/internal/pdf/pdf_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdint>
#include <functional>
#include <memory>
#include <span>
#include <string>
#include <vector>

Expand Down Expand Up @@ -56,7 +57,7 @@ struct ColorSpaceDef {
/// Convert `components` of this space to sRGB in [0, 1]. A short/empty input
/// yields the space's default colour.
[[nodiscard]] std::array<double, 3>
to_rgb(const std::vector<double> &components) const;
to_rgb(std::span<const double> components) const;

/// The initial colour value of the space (ISO 32000-1 8.6.3): all-zero
/// components, except Indexed (index 0) and Separation/DeviceN (tint 1.0).
Expand Down
8 changes: 4 additions & 4 deletions src/odr/internal/pdf/pdf_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ExponentialFunction final : public Function {
m_c1{std::move(c1)}, m_n{n} {}

protected:
std::vector<double> compute(const std::vector<double> &in) const override {
std::vector<double> compute(const std::span<const double> in) const override {
const double x = in.empty() ? 0.0 : in[0];
const double xn = std::pow(x, m_n);
// `/C0` and `/C1` must be equally long; a malformed file may disagree.
Expand Down Expand Up @@ -83,7 +83,7 @@ class StitchingFunction final : public Function {
m_encode{std::move(encode)} {}

protected:
std::vector<double> compute(const std::vector<double> &in) const override {
std::vector<double> compute(const std::span<const double> in) const override {
if (m_functions.empty()) {
return {};
}
Expand Down Expand Up @@ -132,7 +132,7 @@ class SampledFunction final : public Function {
m_decode{std::move(decode)}, m_samples{std::move(samples)} {}

protected:
std::vector<double> compute(const std::vector<double> &in) const override {
std::vector<double> compute(const std::span<const double> in) const override {
const std::size_t m = m_size.size();
const std::size_t n = output_arity();
if (m == 0 || n == 0) {
Expand Down Expand Up @@ -267,7 +267,7 @@ class PostScriptFunction final : public Function {
m_program{std::move(program)} {}

protected:
std::vector<double> compute(const std::vector<double> &in) const override {
std::vector<double> compute(const std::span<const double> in) const override {
std::vector<Item> stack;
stack.reserve(in.size());
for (const double x : in) {
Expand Down
3 changes: 2 additions & 1 deletion src/odr/internal/pdf/pdf_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstddef>
#include <functional>
#include <memory>
#include <span>
#include <string>
#include <vector>

Expand Down Expand Up @@ -35,7 +36,7 @@ class Function {
: m_domain{std::move(domain)}, m_range{std::move(range)} {}

[[nodiscard]] virtual std::vector<double>
compute(const std::vector<double> &in) const = 0;
compute(std::span<const double> in) const = 0;

std::vector<double> m_domain; // [min0 max0 min1 max1 ...]
std::vector<double> m_range; // [min0 max0 ...], possibly empty
Expand Down
2 changes: 1 addition & 1 deletion src/odr/internal/pdf/pdf_graphics_operator_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ GraphicsOperator GraphicsOperatorParser::read_operator() {
}

Dictionary GraphicsOperatorParser::read_inline_image_dictionary(
const std::vector<Object> &arguments) {
const std::span<const Object> arguments) {
// The inline dictionary is a flat run of name/value pairs (8.9.7).
// Abbreviated keys are normalized to their long forms downstream.
Dictionary dictionary;
Expand Down
4 changes: 2 additions & 2 deletions src/odr/internal/pdf/pdf_graphics_operator_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <odr/logger.hpp>

#include <span>
#include <string>
#include <vector>

namespace odr::internal::pdf {

Expand All @@ -29,7 +29,7 @@ class GraphicsOperatorParser {
// Fold an inline image's flat name/value argument run into a dictionary
// (8.9.7); abbreviated keys are normalized to long forms downstream.
[[nodiscard]] static Dictionary
read_inline_image_dictionary(const std::vector<Object> &arguments);
read_inline_image_dictionary(std::span<const Object> arguments);

// Read the binary image data of an inline image, from just after the `ID`
// keyword up to (excluding) its `EI` terminator (8.9.7), leaving the cursor
Expand Down
31 changes: 16 additions & 15 deletions src/odr/internal/pdf/pdf_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ void unpremultiply(std::string &samples, const std::int32_t components,
/// A decoded JPEG 2000 raster as a PNG, through the image's own colour space
/// when the count matches and a device space of its component count otherwise
/// (ISO 32000-1 8.9.5.1: `/ColorSpace` is optional for `JPXDecode`).
std::optional<EncodedImage> encode_jpx(const std::string &data,
const ColorSpaceDef *color_space,
const std::vector<double> &decode_array,
const std::vector<std::uint8_t> &alpha,
const std::vector<double> &color_key,
const std::int32_t smask_in_data) {
std::optional<EncodedImage>
encode_jpx(const std::string &data, const ColorSpaceDef *color_space,
const std::span<const double> decode_array,
const std::span<const std::uint8_t> alpha,
const std::span<const double> color_key,
const std::int32_t smask_in_data) {
std::optional<JpxImage> image = decode_jpx(data);
if (!image.has_value()) {
return std::nullopt;
Expand Down Expand Up @@ -131,7 +131,8 @@ std::optional<EncodedImage> encode_jpx(const std::string &data,

const std::string png = encode_image_png(
image->samples, image->width, image->height, 8, space, decode_array,
alpha.empty() ? image->alpha : alpha, color_key);
alpha.empty() ? std::span<const std::uint8_t>{image->alpha} : alpha,
color_key);
if (png.empty()) {
return std::nullopt;
}
Expand Down Expand Up @@ -190,9 +191,9 @@ std::string pdf::encode_image_png(const std::string &samples,
const std::int32_t height,
const std::int32_t bits_per_component,
const ColorSpaceDef &color_space,
const std::vector<double> &decode,
const std::vector<std::uint8_t> &alpha,
const std::vector<double> &color_key) {
const std::span<const double> decode,
const std::span<const std::uint8_t> alpha,
const std::span<const double> color_key) {
const std::int32_t components = color_space.components;
if (width <= 0 || height <= 0 || components <= 0 || bits_per_component <= 0 ||
bits_per_component > 16) {
Expand Down Expand Up @@ -275,7 +276,7 @@ std::string pdf::encode_image_png(const std::string &samples,
std::vector<std::uint8_t> pdf::decode_mask_alpha(
const std::string &samples, const std::int32_t width,
const std::int32_t height, const std::int32_t bits_per_component,
const std::vector<double> &decode, const bool stencil,
const std::span<const double> decode, const bool stencil,
const std::int32_t base_width, const std::int32_t base_height) {
if (width <= 0 || height <= 0 || base_width <= 0 || base_height <= 0 ||
bits_per_component <= 0 || bits_per_component > 16) {
Expand Down Expand Up @@ -333,7 +334,7 @@ std::string pdf::encode_stencil_png(const std::string &samples,
const std::int32_t width,
const std::int32_t height,
const std::array<double, 3> &color,
const std::vector<double> &decode) {
const std::span<const double> decode) {
if (width <= 0 || height <= 0) {
return {};
}
Expand Down Expand Up @@ -369,9 +370,9 @@ std::optional<pdf::EncodedImage> pdf::encode_image(
std::string raw, const Object &filter, const Object &decode_parms,
const std::int32_t width, const std::int32_t height,
const std::int32_t bits_per_component, const ColorSpaceDef *color_space,
const std::vector<double> &decode_array,
const std::vector<std::uint8_t> &alpha,
const std::vector<double> &color_key, const std::int32_t smask_in_data,
const std::span<const double> decode_array,
const std::span<const std::uint8_t> alpha,
const std::span<const double> color_key, const std::int32_t smask_in_data,
const DecodeOptions &options) {
const std::optional<std::string> terminal = terminal_image_codec(filter);

Expand Down
17 changes: 9 additions & 8 deletions src/odr/internal/pdf/pdf_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <array>
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <vector>

Expand Down Expand Up @@ -34,9 +35,9 @@ std::optional<EncodedImage>
encode_image(std::string raw, const Object &filter, const Object &decode_parms,
std::int32_t width, std::int32_t height,
std::int32_t bits_per_component, const ColorSpaceDef *color_space,
const std::vector<double> &decode,
const std::vector<std::uint8_t> &alpha = {},
const std::vector<double> &color_key = {},
std::span<const double> decode,
std::span<const std::uint8_t> alpha = {},
std::span<const double> color_key = {},
std::int32_t smask_in_data = 0, const DecodeOptions &options = {});

/// Assemble decoded image samples (ISO 32000-1 8.9.5: MSB-first, rows padded
Expand All @@ -50,9 +51,9 @@ std::string encode_image_png(const std::string &samples, std::int32_t width,
std::int32_t height,
std::int32_t bits_per_component,
const ColorSpaceDef &color_space,
const std::vector<double> &decode,
const std::vector<std::uint8_t> &alpha = {},
const std::vector<double> &color_key = {});
std::span<const double> decode,
std::span<const std::uint8_t> alpha = {},
std::span<const double> color_key = {});

/// Resolve a `/SMask` or stencil `/Mask` sub-image into a coverage plane sized
/// to the *base* image, nearest-neighbour resampled β€” the two resolutions need
Expand All @@ -62,7 +63,7 @@ std::string encode_image_png(const std::string &samples, std::int32_t width,
std::vector<std::uint8_t>
decode_mask_alpha(const std::string &samples, std::int32_t width,
std::int32_t height, std::int32_t bits_per_component,
const std::vector<double> &decode, bool stencil,
std::span<const double> decode, bool stencil,
std::int32_t base_width, std::int32_t base_height);

/// Wrap 8-bit pixels (row-major, unpadded) into a PNG: single `IDAT`, no
Expand All @@ -77,6 +78,6 @@ std::string write_png(const std::string &pixels, std::int32_t width,
std::string encode_stencil_png(const std::string &samples, std::int32_t width,
std::int32_t height,
const std::array<double, 3> &color,
const std::vector<double> &decode);
std::span<const double> decode);

} // namespace odr::internal::pdf
4 changes: 3 additions & 1 deletion test/src/internal/font/type1_charstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gtest/gtest.h>

#include <array>
#include <string>
#include <vector>

Expand Down Expand Up @@ -81,7 +82,8 @@ TEST(Type1CharstringTest, FlattensCallSubr) {
op(t1, 10); // callsubr 0
op(t1, 14); // endchar

const Type2Charstring out = to_type2(t1, {subr0});
const std::array<std::string, 1> subrs = {subr0};
const Type2Charstring out = to_type2(t1, subrs);

// The subr's rlineto is inlined; expect width(0) rmoveto, then rlineto, then
// endchar.
Expand Down
Loading
Loading