-
Notifications
You must be signed in to change notification settings - Fork 237
Move harfbuzz-traits implementations into component crates
#7200
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // This file is part of ICU4X. For terms of use, please see the file | ||
| // called LICENSE at the top level of the ICU4X source tree | ||
| // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
|
||
| use crate::properties::{ | ||
| CanonicalCombiningClassMap, CanonicalCombiningClassMapBorrowed, CanonicalComposition, | ||
| CanonicalCompositionBorrowed, CanonicalDecomposition, CanonicalDecompositionBorrowed, | ||
| Decomposed, | ||
| }; | ||
| use harfbuzz_traits::{CombiningClassFunc, ComposeFunc, DecomposeFunc}; | ||
|
|
||
| impl ComposeFunc for CanonicalCompositionBorrowed<'_> { | ||
| fn compose(&self, a: char, b: char) -> Option<char> { | ||
| CanonicalCompositionBorrowed::compose(*self, a, b) | ||
| } | ||
| } | ||
|
|
||
| impl ComposeFunc for CanonicalComposition { | ||
| fn compose(&self, a: char, b: char) -> Option<char> { | ||
| ComposeFunc::compose(&self.as_borrowed(), a, b) | ||
| } | ||
| } | ||
|
|
||
| impl ComposeFunc for &'_ CanonicalComposition { | ||
| fn compose(&self, a: char, b: char) -> Option<char> { | ||
| ComposeFunc::compose(&self.as_borrowed(), a, b) | ||
| } | ||
| } | ||
|
|
||
| impl DecomposeFunc for CanonicalDecompositionBorrowed<'_> { | ||
| fn decompose(&self, ab: char) -> Option<(char, char)> { | ||
| match CanonicalDecompositionBorrowed::decompose(self, ab) { | ||
| Decomposed::Default => None, | ||
| Decomposed::Expansion(first, second) => Some((first, second)), | ||
| Decomposed::Singleton(single) => Some((single, '\0')), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl DecomposeFunc for CanonicalDecomposition { | ||
| fn decompose(&self, ab: char) -> Option<(char, char)> { | ||
| DecomposeFunc::decompose(&self.as_borrowed(), ab) | ||
| } | ||
| } | ||
|
|
||
| impl DecomposeFunc for &'_ CanonicalDecomposition { | ||
| fn decompose(&self, ab: char) -> Option<(char, char)> { | ||
| DecomposeFunc::decompose(&self.as_borrowed(), ab) | ||
| } | ||
| } | ||
|
|
||
| impl CombiningClassFunc for CanonicalCombiningClassMapBorrowed<'_> { | ||
| fn combining_class(&self, ch: char) -> u8 { | ||
| self.get_u8(ch) | ||
| } | ||
| } | ||
|
|
||
| impl CombiningClassFunc for CanonicalCombiningClassMap { | ||
| fn combining_class(&self, ch: char) -> u8 { | ||
| CombiningClassFunc::combining_class(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl CombiningClassFunc for &'_ CanonicalCombiningClassMap { | ||
| fn combining_class(&self, ch: char) -> u8 { | ||
| CombiningClassFunc::combining_class(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| // This file is part of ICU4X. For terms of use, please see the file | ||
| // called LICENSE at the top level of the ICU4X source tree | ||
| // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
|
||
| use crate::props::{BidiMirroringGlyph, GeneralCategory, Script}; | ||
| use crate::provider::{PropertyEnumScriptV1, PropertyNameShortScriptV1}; | ||
| use crate::{ | ||
| CodePointMapData, CodePointMapDataBorrowed, PropertyNamesShort, PropertyNamesShortBorrowed, | ||
| }; | ||
| use icu_provider::prelude::*; | ||
|
|
||
| use harfbuzz_traits::{GeneralCategoryFunc, MirroringFunc, ScriptFunc}; | ||
|
|
||
| impl GeneralCategoryFunc for CodePointMapDataBorrowed<'_, GeneralCategory> { | ||
| fn general_category(&self, ch: char) -> harfbuzz_traits::GeneralCategory { | ||
| self.get(ch).into() | ||
| } | ||
| } | ||
|
|
||
| impl GeneralCategoryFunc for CodePointMapData<GeneralCategory> { | ||
| fn general_category(&self, ch: char) -> harfbuzz_traits::GeneralCategory { | ||
| GeneralCategoryFunc::general_category(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl GeneralCategoryFunc for &'_ CodePointMapData<GeneralCategory> { | ||
| fn general_category(&self, ch: char) -> harfbuzz_traits::GeneralCategory { | ||
| GeneralCategoryFunc::general_category(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl MirroringFunc for CodePointMapDataBorrowed<'_, BidiMirroringGlyph> { | ||
| fn mirroring(&self, ch: char) -> char { | ||
| self.get(ch).mirroring_glyph.unwrap_or(ch) | ||
| } | ||
| } | ||
|
|
||
| impl MirroringFunc for CodePointMapData<BidiMirroringGlyph> { | ||
| fn mirroring(&self, ch: char) -> char { | ||
| MirroringFunc::mirroring(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl MirroringFunc for &'_ CodePointMapData<BidiMirroringGlyph> { | ||
| fn mirroring(&self, ch: char) -> char { | ||
| MirroringFunc::mirroring(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl ScriptFunc for HarfbuzzScriptDataBorrowed<'_> { | ||
| fn script(&self, ch: char) -> [u8; 4] { | ||
| let script = self.script.get(ch); | ||
| self.script_names | ||
| .get_locale_script(script) | ||
| .unwrap_or(icu_locale_core::subtags::script!("Zzzz")) | ||
| .into_raw() | ||
| } | ||
| } | ||
|
|
||
| impl ScriptFunc for HarfbuzzScriptData { | ||
| fn script(&self, ch: char) -> [u8; 4] { | ||
| ScriptFunc::script(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl ScriptFunc for &'_ HarfbuzzScriptData { | ||
| fn script(&self, ch: char) -> [u8; 4] { | ||
| ScriptFunc::script(&self.as_borrowed(), ch) | ||
| } | ||
| } | ||
|
|
||
| impl From<GeneralCategory> for harfbuzz_traits::GeneralCategory { | ||
| fn from(val: GeneralCategory) -> Self { | ||
| use GeneralCategory::*; | ||
| match val { | ||
| Unassigned => harfbuzz_traits::GeneralCategory::Unassigned, | ||
| UppercaseLetter => harfbuzz_traits::GeneralCategory::UppercaseLetter, | ||
| LowercaseLetter => harfbuzz_traits::GeneralCategory::LowercaseLetter, | ||
| TitlecaseLetter => harfbuzz_traits::GeneralCategory::TitlecaseLetter, | ||
| ModifierLetter => harfbuzz_traits::GeneralCategory::ModifierLetter, | ||
| OtherLetter => harfbuzz_traits::GeneralCategory::OtherLetter, | ||
| NonspacingMark => harfbuzz_traits::GeneralCategory::NonSpacingMark, | ||
| SpacingMark => harfbuzz_traits::GeneralCategory::SpacingMark, | ||
| EnclosingMark => harfbuzz_traits::GeneralCategory::EnclosingMark, | ||
| DecimalNumber => harfbuzz_traits::GeneralCategory::DecimalNumber, | ||
| LetterNumber => harfbuzz_traits::GeneralCategory::LetterNumber, | ||
| OtherNumber => harfbuzz_traits::GeneralCategory::OtherNumber, | ||
| SpaceSeparator => harfbuzz_traits::GeneralCategory::SpaceSeparator, | ||
| LineSeparator => harfbuzz_traits::GeneralCategory::LineSeparator, | ||
| ParagraphSeparator => harfbuzz_traits::GeneralCategory::ParagraphSeparator, | ||
| Control => harfbuzz_traits::GeneralCategory::Control, | ||
| Format => harfbuzz_traits::GeneralCategory::Format, | ||
| PrivateUse => harfbuzz_traits::GeneralCategory::PrivateUse, | ||
| Surrogate => harfbuzz_traits::GeneralCategory::Surrogate, | ||
| DashPunctuation => harfbuzz_traits::GeneralCategory::DashPunctuation, | ||
| OpenPunctuation => harfbuzz_traits::GeneralCategory::OpenPunctuation, | ||
| ClosePunctuation => harfbuzz_traits::GeneralCategory::ClosePunctuation, | ||
| ConnectorPunctuation => harfbuzz_traits::GeneralCategory::ConnectPunctuation, | ||
| InitialPunctuation => harfbuzz_traits::GeneralCategory::InitialPunctuation, | ||
| FinalPunctuation => harfbuzz_traits::GeneralCategory::FinalPunctuation, | ||
| OtherPunctuation => harfbuzz_traits::GeneralCategory::OtherPunctuation, | ||
| MathSymbol => harfbuzz_traits::GeneralCategory::MathSymbol, | ||
| CurrencySymbol => harfbuzz_traits::GeneralCategory::CurrencySymbol, | ||
| ModifierSymbol => harfbuzz_traits::GeneralCategory::ModifierSymbol, | ||
| OtherSymbol => harfbuzz_traits::GeneralCategory::OtherSymbol, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Harfbuzz data for the [`ScriptFunc`] implementation | ||
| #[derive(Debug)] | ||
| pub struct HarfbuzzScriptDataBorrowed<'a> { | ||
| script: CodePointMapDataBorrowed<'a, Script>, | ||
| script_names: PropertyNamesShortBorrowed<'a, Script>, | ||
| } | ||
|
|
||
| /// Harfbuzz data for the [`ScriptFunc`] implementation | ||
| #[derive(Debug)] | ||
| pub struct HarfbuzzScriptData { | ||
| script: CodePointMapData<Script>, | ||
| script_names: PropertyNamesShort<Script>, | ||
| } | ||
|
|
||
| impl HarfbuzzScriptData { | ||
| #[cfg(feature = "compiled_data")] | ||
| /// Construct a new [`HarfbuzzScriptData`] using compiled data. | ||
| #[expect(clippy::new_ret_no_self)] | ||
| pub fn new() -> HarfbuzzScriptDataBorrowed<'static> { | ||
| HarfbuzzScriptDataBorrowed { | ||
| script: CodePointMapData::<Script>::new(), | ||
| script_names: PropertyNamesShort::<Script>::new(), | ||
| } | ||
| } | ||
|
|
||
| /// Construct a new [`HarfbuzzScriptData`] from a data provider. | ||
| pub fn try_new_unstable<D>(provider: &D) -> Result<Self, DataError> | ||
| where | ||
| D: DataProvider<PropertyEnumScriptV1> + DataProvider<PropertyNameShortScriptV1> + ?Sized, | ||
| { | ||
| let script_set = CodePointMapData::<Script>::try_new_unstable(provider)?; | ||
| let script_names = PropertyNamesShort::try_new_unstable(provider)?; | ||
| Ok(Self { | ||
| script: script_set, | ||
| script_names, | ||
| }) | ||
| } | ||
|
|
||
| #[cfg(feature = "serde")] | ||
| #[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER,Self::try_new_unstable)] | ||
| pub fn try_new_with_buffer_provider( | ||
| provider: &(impl icu_provider::buf::BufferProvider + ?Sized), | ||
| ) -> Result<Self, DataError> { | ||
| Self::try_new_unstable(&provider.as_deserializing()) | ||
| } | ||
|
|
||
| fn as_borrowed(&self) -> HarfbuzzScriptDataBorrowed<'_> { | ||
| HarfbuzzScriptDataBorrowed { | ||
| script: self.script.as_borrowed(), | ||
| script_names: self.script_names.as_borrowed(), | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.