Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature image occlusion #2367

Merged
merged 39 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
da69975
add note types with occlusions and image fields
krmanik Feb 14, 2023
3e43b0c
generate image occlusion cloze div data
krmanik Feb 14, 2023
3a3b41b
getting image data & deck id and adding notes
krmanik Feb 14, 2023
dc74eb4
script for generating shapes using canvas api in reviewer
krmanik Feb 14, 2023
fe2adf2
init image occlusion page in ts and build page
krmanik Feb 14, 2023
a1b4739
implement top toolbar for canvas shapes
krmanik Feb 14, 2023
cea2861
implement side toolbar for drawing shapes
krmanik Feb 14, 2023
3054473
add maskeditor page for editing mask
krmanik Feb 14, 2023
b74694c
implement note editor page for adding notes
krmanik Feb 14, 2023
ef8fc22
add image occlusion page
krmanik Feb 14, 2023
0fd7c96
implement generates notes and save notes
krmanik Feb 14, 2023
24acfab
removed pickr & implemented color picker component
krmanik Feb 22, 2023
f81e6b2
rename methods name & rust unwrap safety
krmanik Feb 22, 2023
7828902
extract to function & add comments & remove global
krmanik Feb 22, 2023
bf16cab
remove image_occlusion notetype
krmanik Feb 28, 2023
8c66a66
update smooth scroll, always show cursor tools
krmanik Feb 28, 2023
ab68f92
add and get notetype else return errors
krmanik Feb 28, 2023
c42eb0a
fix: not showing occlusion
krmanik Mar 1, 2023
a4f8a3d
Use a oneof for ImageClozeNoteResponse
dae Mar 1, 2023
f57bf3f
Don't crash if image filename not provided
dae Mar 1, 2023
a0c6c7a
Refactor get_image_cloze_note
dae Mar 1, 2023
114b0b5
Fix crash if image file unreadable
dae Mar 1, 2023
88b9e5d
Add metadata() helper
dae Mar 1, 2023
7a1ef55
Fix crash if file metadata can't be read
dae Mar 1, 2023
e135566
remove color picker, qmask and shape color
krmanik Mar 3, 2023
385d74c
update color in reviewer and ftl strings
krmanik Mar 3, 2023
e34ff14
fix shape position in canvas & add border to shape
krmanik Mar 4, 2023
95904b7
fix shape position in canvas after modified
krmanik Mar 6, 2023
5e59e17
fix border width and color in reviewer canvas
krmanik Mar 6, 2023
94108da
refactor cloze div generate and remove angle
krmanik Mar 7, 2023
80b8468
fix origin when drawn outside of canvas from right
krmanik Mar 7, 2023
7c26696
fix shape at boundry & not include rx,ry rectangle
krmanik Mar 10, 2023
86d8a15
fix lint errors & update image size in editor canvas based on height …
krmanik Mar 10, 2023
bfb18d3
remove unsupported layerX & layerX for touchscreen
krmanik Mar 10, 2023
357e684
implemented undo redo with canvas state
krmanik Mar 11, 2023
06b7ba7
remove background image from canvas and used css to put image tag bel…
krmanik Mar 11, 2023
14e5fb3
fix for polygon points, add br in cloze strings, & toogle masks button
krmanik Mar 11, 2023
7ae3cd9
refactor top toolbar, add space and border radius
krmanik Mar 11, 2023
da2aad7
fix undo after undo happen, use transparent color in draw mode
krmanik Mar 28, 2023
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
12 changes: 12 additions & 0 deletions build/configure/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ fn build_and_check_pages(build: &mut Build) -> Result<()> {
":sass"
],
)?;
build_page(
"image-occlusion",
true,
inputs![
//
":ts:lib",
":ts:components",
":ts:sveltelib",
":ts:tag-editor",
":sass"
],
)?;

Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions ftl/core/importing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ importing-tag-updated-notes = Tag updated notes
importing-file = File
importing-match-scope = Match scope
importing-notetype-and-deck = Notetype and deck
importing-cards-added =
{ $count ->
[one] { $count } card added.
*[other] { $count } cards added.
}

## NO NEED TO TRANSLATE. This text is no longer used by Anki, and will be removed in the future.

Expand Down
15 changes: 15 additions & 0 deletions ftl/core/notetypes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ notetypes-note-types = Note Types
notetypes-options = Options
notetypes-please-add-another-note-type-first = Please add another note type first.
notetypes-type = Type

## Image Occlusion

notetypes-image = Image
notetypes-occlusion = Occlusion
notetypes-occlusion-mask = Mask
notetypes-occlusion-note = Note
notetypes-comments-field = Comments
notetypes-toggle-masks = Toggle Masks
notetypes-image-occlusion-name = Image Occlusion
notetypes-hide-all-guess-one = Hide All, Guess One
notetypes-hide-one-guess-one = Hide One, Guess One
notetypes-error-generating-cloze = An error occurred when generating an image occlusion note
notetypes-error-getting-imagecloze = An error occurred while fetching an image occlusion note
notetypes-error-loading-image-occlusion = Error loading image occlusion. Is your Anki version up to date?
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"codemirror": "^5.63.1",
"css-browser-selector": "^0.6.5",
"d3": "^7.0.0",
"fabric": "^5.3.0",
"fuse.js": "^6.6.2",
"gemoji": "^7.1.0",
"intl-pluralrules": "^1.2.2",
Expand All @@ -82,6 +83,7 @@
"lodash-es": "^4.17.21",
"marked": "^4.0.0",
"mathjax": "^3.1.2",
"panzoom": "^9.4.3",
"protobufjs": "^7"
},
"resolutions": {
Expand Down
1 change: 1 addition & 0 deletions proto/anki/backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum ServiceIndex {
SERVICE_INDEX_LINKS = 15;
SERVICE_INDEX_IMPORT_EXPORT = 16;
SERVICE_INDEX_ANKIDROID = 17;
SERVICE_INDEX_IMAGE_OCCLUSION = 18;
}

message BackendInit {
Expand Down
67 changes: 67 additions & 0 deletions proto/anki/image_occlusion.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

syntax = "proto3";

option java_multiple_files = true;

package anki.image_occlusion;

import "anki/cards.proto";
import "anki/collection.proto";
import "anki/notes.proto";
import "anki/generic.proto";

service ImageOcclusionService {
rpc GetImageForOcclusion(GetImageForOcclusionRequest) returns (ImageData);
rpc AddImageOcclusionNote(AddImageOcclusionNoteRequest)
returns (collection.OpChanges);
rpc GetImageClozeNote(GetImageOcclusionNoteRequest)
returns (ImageClozeNoteResponse);
rpc UpdateImageOcclusionNote(UpdateImageOcclusionNoteRequest)
returns (collection.OpChanges);
}

message GetImageForOcclusionRequest {
string path = 1;
}

message ImageData {
bytes data = 1;
string name = 2;
}

message AddImageOcclusionNoteRequest {
string image_path = 1;
string occlusions = 2;
string header = 3;
string back_extra = 4;
repeated string tags = 5;
}

message ImageClozeNote {
bytes image_data = 1;
string occlusions = 2;
string header = 3;
string back_extra = 4;
repeated string tags = 5;
}

message GetImageOcclusionNoteRequest {
int64 note_id = 1;
}

message UpdateImageOcclusionNoteRequest {
int64 note_id = 1;
string occlusions = 2;
string header = 3;
string back_extra = 4;
repeated string tags = 5;
}

message ImageClozeNoteResponse {
oneof value {
ImageClozeNote note = 1;
string error = 2;
}
}
1 change: 1 addition & 0 deletions proto/anki/notetypes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ message StockNotetype {
BASIC_OPTIONAL_REVERSED = 2;
BASIC_TYPING = 3;
CLOZE = 4;
IMAGE_OCCLUSION = 5;
}

Kind kind = 1;
Expand Down
44 changes: 44 additions & 0 deletions pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
collection_pb2,
config_pb2,
generic_pb2,
image_occlusion_pb2,
import_export_pb2,
links_pb2,
search_pb2,
Expand Down Expand Up @@ -40,6 +41,9 @@
DupeResolution = CsvMetadata.DupeResolution
Delimiter = import_export_pb2.CsvMetadata.Delimiter
TtsVoice = card_rendering_pb2.AllTtsVoicesResponse.TtsVoice
ImageData = image_occlusion_pb2.ImageData
AddImageOcclusionNoteRequest = image_occlusion_pb2.AddImageOcclusionNoteRequest
ImageClozeNoteResponse = image_occlusion_pb2.ImageClozeNoteResponse

import copy
import os
Expand Down Expand Up @@ -456,6 +460,46 @@ def import_json_file(self, path: str) -> ImportLogWithChanges:
def import_json_string(self, json: str) -> ImportLogWithChanges:
return self._backend.import_json_string(json)

# Image Occlusion
##########################################################################
def get_image_for_occlusion(self, path: str | None) -> ImageData:
return self._backend.get_image_for_occlusion(path=path)

def add_image_occlusion_note(
self,
image_path: str | None,
occlusions: str | None,
header: str | None,
back_extra: str | None,
tags: list[str] | None,
) -> OpChanges:
return self._backend.add_image_occlusion_note(
image_path=image_path,
occlusions=occlusions,
header=header,
back_extra=back_extra,
tags=tags,
)

def get_image_cloze_note(self, note_id: int | None) -> ImageClozeNoteResponse:
return self._backend.get_image_cloze_note(note_id=note_id)

def update_image_occlusion_note(
self,
note_id: int | None,
occlusions: str | None,
header: str | None,
back_extra: str | None,
tags: list[str] | None,
) -> OpChanges:
return self._backend.update_image_occlusion_note(
note_id=note_id,
occlusions=occlusions,
header=header,
back_extra=back_extra,
tags=tags,
)

# Object helpers
##########################################################################

Expand Down
3 changes: 3 additions & 0 deletions pylib/tools/genbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import anki.deckconfig_pb2
import anki.decks_pb2
import anki.i18n_pb2
import anki.image_occlusion_pb2
import anki.import_export_pb2
import anki.links_pb2
import anki.media_pb2
Expand Down Expand Up @@ -187,6 +188,7 @@ def render_service(
MEDIA=anki.media_pb2,
LINKS=anki.links_pb2,
IMPORT_EXPORT=anki.import_export_pb2,
IMAGE_OCCLUSION=anki.image_occlusion_pb2,
)

for service in anki.backend_pb2.ServiceIndex.DESCRIPTOR.values:
Expand Down Expand Up @@ -238,6 +240,7 @@ def render_service(
import anki.tags_pb2
import anki.media_pb2
import anki.import_export_pb2
import anki.image_occlusion_pb2

class RustBackendGenerated:
def _run_command(self, service: int, method: int, input: Any) -> bytes:
Expand Down
5 changes: 5 additions & 0 deletions qt/aqt/mediasrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ def handle_on_main() -> None:
"set_graph_preferences",
# TagsService
"complete_tag",
# ImageOcclusionService
"get_image_for_occlusion",
"add_image_occlusion_note",
"get_image_cloze_note",
"update_image_occlusion_note",
]


Expand Down
55 changes: 55 additions & 0 deletions rslib/src/backend/image_occlusion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

use super::Backend;
pub(super) use crate::pb::image_occlusion::imageocclusion_service::Service as ImageOcclusionService;
use crate::pb::{self as pb,};
use crate::prelude::*;

impl ImageOcclusionService for Backend {
fn get_image_for_occlusion(
&self,
input: pb::image_occlusion::GetImageForOcclusionRequest,
) -> Result<pb::image_occlusion::ImageData> {
self.with_col(|col| col.get_image_for_occlusion(&input.path))
}

fn add_image_occlusion_note(
&self,
input: pb::image_occlusion::AddImageOcclusionNoteRequest,
) -> Result<pb::collection::OpChanges> {
self.with_col(|col| {
col.add_image_occlusion_note(
&input.image_path,
&input.occlusions,
&input.header,
&input.back_extra,
input.tags,
)
})
.map(Into::into)
}

fn get_image_cloze_note(
&self,
input: pb::image_occlusion::GetImageOcclusionNoteRequest,
) -> Result<pb::image_occlusion::ImageClozeNoteResponse> {
self.with_col(|col| col.get_image_cloze_note(input.note_id.into()))
}

fn update_image_occlusion_note(
&self,
input: pb::image_occlusion::UpdateImageOcclusionNoteRequest,
) -> Result<pb::collection::OpChanges> {
self.with_col(|col| {
col.update_image_occlusion_note(
input.note_id.into(),
&input.occlusions,
&input.header,
&input.back_extra,
input.tags,
)
})
.map(Into::into)
}
}
5 changes: 5 additions & 0 deletions rslib/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod decks;
mod error;
mod generic;
mod i18n;
mod image_occlusion;
mod import_export;
mod links;
mod media;
Expand Down Expand Up @@ -48,6 +49,7 @@ use self::config::ConfigService;
use self::deckconfig::DeckConfigService;
use self::decks::DecksService;
use self::i18n::I18nService;
use self::image_occlusion::ImageOcclusionService;
use self::import_export::ImportExportService;
use self::links::LinksService;
use self::media::MediaService;
Expand Down Expand Up @@ -142,6 +144,9 @@ impl Backend {
ServiceIndex::Collection => CollectionService::run_method(self, method, input),
ServiceIndex::Cards => CardsService::run_method(self, method, input),
ServiceIndex::ImportExport => ImportExportService::run_method(self, method, input),
ServiceIndex::ImageOcclusion => {
ImageOcclusionService::run_method(self, method, input)
}
})
.map_err(|err| {
let backend_err = err.into_protobuf(&self.tr);
Expand Down
Loading