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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ The release run heads these entries with the version and opens a fresh

## Unreleased

- An ODF drawing shape is drawn where its `draw:transform` puts it. New
`transform()` on `Frame`, `Rect`, `Line`, `Circle` and `CustomShape`,
mirrored in the JNI, Apple and Python bindings.

- A StarView metafile's text is decoded by the charset it names. Every
encoding but `UCS2` used to emit the file's own bytes, and the invalid utf-8
a non-ascii label made of that cost the whole image.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ set(ODR_SOURCE_FILES
"src/odr/internal/odf/odf_element_registry.cpp"
"src/odr/internal/odf/odf_file.cpp"
"src/odr/internal/odf/odf_flat_file.cpp"
"src/odr/internal/odf/odf_geometry.cpp"
"src/odr/internal/odf/odf_list.cpp"
"src/odr/internal/odf/odf_manifest.cpp"
"src/odr/internal/odf/odf_meta.cpp"
Expand Down
19 changes: 19 additions & 0 deletions apple/include/OdrCoreObjC/ODRDocumentElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ NS_SWIFT_NAME(TableCell)
@property(nonatomic, readonly) ODRTableCellStyle *style;
@end

/// `odr::DrawingTransform`.
NS_SWIFT_NAME(DrawingTransform)
@interface ODRDrawingTransform : NSObject
@property(nonatomic, readonly) double a;
@property(nonatomic, readonly) double b;
@property(nonatomic, readonly) double c;
@property(nonatomic, readonly) double d;
@property(nonatomic, readonly) ODRMeasure *e;
@property(nonatomic, readonly) ODRMeasure *f;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@end

/// `odr::Frame`.
NS_SWIFT_NAME(Frame)
@interface ODRFrame : ODRElement
Expand All @@ -259,6 +273,7 @@ NS_SWIFT_NAME(Frame)
@property(nonatomic, readonly, nullable) ODRMeasure *height;
/// `int32_t`, boxed; `nil` when the document did not set one.
@property(nonatomic, readonly, nullable) NSNumber *zIndex;
@property(nonatomic, readonly, nullable) ODRDrawingTransform *transform;
@property(nonatomic, readonly) ODRGraphicStyle *style;
@end

Expand All @@ -269,6 +284,7 @@ NS_SWIFT_NAME(Rect)
@property(nonatomic, readonly) ODRMeasure *y;
@property(nonatomic, readonly) ODRMeasure *width;
@property(nonatomic, readonly) ODRMeasure *height;
@property(nonatomic, readonly, nullable) ODRDrawingTransform *transform;
@property(nonatomic, readonly) ODRGraphicStyle *style;
@end

Expand All @@ -279,6 +295,7 @@ NS_SWIFT_NAME(Line)
@property(nonatomic, readonly) ODRMeasure *y1;
@property(nonatomic, readonly) ODRMeasure *x2;
@property(nonatomic, readonly) ODRMeasure *y2;
@property(nonatomic, readonly, nullable) ODRDrawingTransform *transform;
@property(nonatomic, readonly) ODRGraphicStyle *style;
@end

Expand All @@ -289,6 +306,7 @@ NS_SWIFT_NAME(Circle)
@property(nonatomic, readonly) ODRMeasure *y;
@property(nonatomic, readonly) ODRMeasure *width;
@property(nonatomic, readonly) ODRMeasure *height;
@property(nonatomic, readonly, nullable) ODRDrawingTransform *transform;
@property(nonatomic, readonly) ODRGraphicStyle *style;
@end

Expand All @@ -299,6 +317,7 @@ NS_SWIFT_NAME(CustomShape)
@property(nonatomic, readonly, nullable) ODRMeasure *y;
@property(nonatomic, readonly) ODRMeasure *width;
@property(nonatomic, readonly) ODRMeasure *height;
@property(nonatomic, readonly, nullable) ODRDrawingTransform *transform;
@property(nonatomic, readonly) ODRGraphicStyle *style;
@end

Expand Down
64 changes: 64 additions & 0 deletions apple/src/ODRDocumentElement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ - (nullable NSNumber *)zIndex {
nil);
}

- (nullable ODRDrawingTransform *)transform {
return guarded_value(
[&]() -> ODRDrawingTransform * {
return [ODRDrawingTransform
transformWithHandle:self.handle.as_frame().transform()];
},
nil);
}

- (ODRGraphicStyle *)style {
return guarded_value(
[&]() -> ODRGraphicStyle * {
Expand All @@ -743,6 +752,25 @@ - (ODRGraphicStyle *)style {

@end

@implementation ODRDrawingTransform

+ (nullable instancetype)transformWithHandle:
(const std::optional<odr::DrawingTransform> &)handle {
if (!handle.has_value()) {
return nil;
}
ODRDrawingTransform *const result = [[ODRDrawingTransform alloc] init];
result->_a = handle->a;
result->_b = handle->b;
result->_c = handle->c;
result->_d = handle->d;
result->_e = [ODRMeasure measureWithHandle:handle->e];
result->_f = [ODRMeasure measureWithHandle:handle->f];
return result;
}

@end

@implementation ODRRect

- (ODRMeasure *)x {
Expand Down Expand Up @@ -773,6 +801,15 @@ - (ODRMeasure *)height {
nil);
}

- (nullable ODRDrawingTransform *)transform {
return guarded_value(
[&]() -> ODRDrawingTransform * {
return [ODRDrawingTransform
transformWithHandle:self.handle.as_rect().transform()];
},
nil);
}

- (ODRGraphicStyle *)style {
return guarded_value(
[&]() -> ODRGraphicStyle * {
Expand Down Expand Up @@ -809,6 +846,15 @@ - (ODRMeasure *)y2 {
nil);
}

- (nullable ODRDrawingTransform *)transform {
return guarded_value(
[&]() -> ODRDrawingTransform * {
return [ODRDrawingTransform
transformWithHandle:self.handle.as_line().transform()];
},
nil);
}

- (ODRGraphicStyle *)style {
return guarded_value(
[&]() -> ODRGraphicStyle * {
Expand Down Expand Up @@ -853,6 +899,15 @@ - (ODRMeasure *)height {
nil);
}

- (nullable ODRDrawingTransform *)transform {
return guarded_value(
[&]() -> ODRDrawingTransform * {
return [ODRDrawingTransform
transformWithHandle:self.handle.as_circle().transform()];
},
nil);
}

- (ODRGraphicStyle *)style {
return guarded_value(
[&]() -> ODRGraphicStyle * {
Expand Down Expand Up @@ -894,6 +949,15 @@ - (ODRMeasure *)height {
nil);
}

- (nullable ODRDrawingTransform *)transform {
return guarded_value(
[&]() -> ODRDrawingTransform * {
return [ODRDrawingTransform
transformWithHandle:self.handle.as_custom_shape().transform()];
},
nil);
}

- (ODRGraphicStyle *)style {
return guarded_value(
[&]() -> ODRGraphicStyle * {
Expand Down
5 changes: 5 additions & 0 deletions apple/src/ODRPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)styleWithHandle:(const odr::TableCellStyle &)handle;
@end

@interface ODRDrawingTransform (Private)
+ (nullable instancetype)transformWithHandle:
(const std::optional<odr::DrawingTransform> &)handle;
@end

@interface ODRGraphicStyle (Private)
+ (instancetype)styleWithHandle:(const odr::GraphicStyle &)handle;
@end
Expand Down
1 change: 1 addition & 0 deletions jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ add_jar(odr_java
"java/app/opendocument/core/DocumentFile.java"
"java/app/opendocument/core/DocumentPath.java"
"java/app/opendocument/core/DocumentType.java"
"java/app/opendocument/core/DrawingTransform.java"
"java/app/opendocument/core/Element.java"
"java/app/opendocument/core/ElementType.java"
"java/app/opendocument/core/EncryptionState.java"
Expand Down
6 changes: 6 additions & 0 deletions jni/java/app/opendocument/core/Circle.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Measure height() {
return heightNative(handle());
}

public DrawingTransform transform() {
return transformNative(handle());
}

public GraphicStyle style() {
return styleNative(handle());
}
Expand All @@ -34,5 +38,7 @@ public GraphicStyle style() {

private native Measure heightNative(long handle);

private native DrawingTransform transformNative(long handle);

private native GraphicStyle styleNative(long handle);
}
6 changes: 6 additions & 0 deletions jni/java/app/opendocument/core/CustomShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Measure height() {
return heightNative(handle());
}

public DrawingTransform transform() {
return transformNative(handle());
}

public GraphicStyle style() {
return styleNative(handle());
}
Expand All @@ -34,5 +38,7 @@ public GraphicStyle style() {

private native Measure heightNative(long handle);

private native DrawingTransform transformNative(long handle);

private native GraphicStyle styleNative(long handle);
}
43 changes: 43 additions & 0 deletions jni/java/app/opendocument/core/DrawingTransform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package app.opendocument.core;

import java.util.Objects;

/** The affine transform a drawing shape carries. Mirrors {@code odr::DrawingTransform}. */
public final class DrawingTransform {
public final double a;
public final double b;
public final double c;
public final double d;
public final Measure e;
public final Measure f;

public DrawingTransform(double a, double b, double c, double d, Measure e, Measure f) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = Objects.requireNonNull(e);
this.f = Objects.requireNonNull(f);
}

@Override
public boolean equals(Object other) {
return other instanceof DrawingTransform transform
&& a == transform.a
&& b == transform.b
&& c == transform.c
&& d == transform.d
&& e.equals(transform.e)
&& f.equals(transform.f);
}

@Override
public int hashCode() {
return Objects.hash(a, b, c, d, e, f);
}

@Override
public String toString() {
return "matrix(" + a + " " + b + " " + c + " " + d + " " + e + " " + f + ")";
}
}
6 changes: 6 additions & 0 deletions jni/java/app/opendocument/core/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public Integer zIndex() {
return zIndexNative(handle());
}

public DrawingTransform transform() {
return transformNative(handle());
}

public GraphicStyle style() {
return styleNative(handle());
}
Expand All @@ -46,5 +50,7 @@ public GraphicStyle style() {

private native Integer zIndexNative(long handle);

private native DrawingTransform transformNative(long handle);

private native GraphicStyle styleNative(long handle);
}
6 changes: 6 additions & 0 deletions jni/java/app/opendocument/core/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Measure y2() {
return y2Native(handle());
}

public DrawingTransform transform() {
return transformNative(handle());
}

public GraphicStyle style() {
return styleNative(handle());
}
Expand All @@ -34,5 +38,7 @@ public GraphicStyle style() {

private native Measure y2Native(long handle);

private native DrawingTransform transformNative(long handle);

private native GraphicStyle styleNative(long handle);
}
6 changes: 6 additions & 0 deletions jni/java/app/opendocument/core/Rect.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Measure height() {
return heightNative(handle());
}

public DrawingTransform transform() {
return transformNative(handle());
}

public GraphicStyle style() {
return styleNative(handle());
}
Expand All @@ -34,5 +38,7 @@ public GraphicStyle style() {

private native Measure heightNative(long handle);

private native DrawingTransform transformNative(long handle);

private native GraphicStyle styleNative(long handle);
}
4 changes: 4 additions & 0 deletions jni/src/jni_convert.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <odr/document_element.hpp>
#include <odr/file.hpp>
#include <odr/html.hpp>
#include <odr/style.hpp>
Expand Down Expand Up @@ -34,6 +35,9 @@ jobject make_table_column_style(JNIEnv *env,
jobject make_table_row_style(JNIEnv *env, const odr::TableRowStyle &style);
jobject make_table_cell_style(JNIEnv *env, const odr::TableCellStyle &style);
jobject make_graphic_style(JNIEnv *env, const odr::GraphicStyle &style);
jobject
make_drawing_transform(JNIEnv *env,
const std::optional<odr::DrawingTransform> &transform);
jobject make_page_layout(JNIEnv *env, const odr::PageLayout &layout);
jobject make_table_dimensions(JNIEnv *env,
const odr::TableDimensions &dimensions);
Expand Down
Loading
Loading