diff --git a/pxr/usd/CMakeLists.txt b/pxr/usd/CMakeLists.txt index 11452dde43..1aaf79a1a4 100644 --- a/pxr/usd/CMakeLists.txt +++ b/pxr/usd/CMakeLists.txt @@ -16,6 +16,7 @@ set(DIRS usdHydra usdRi usdSkel + usdText usdUI usdUtils usdPhysics diff --git a/pxr/usd/usdText/CMakeLists.txt b/pxr/usd/usdText/CMakeLists.txt new file mode 100644 index 0000000000..796219f142 --- /dev/null +++ b/pxr/usd/usdText/CMakeLists.txt @@ -0,0 +1,59 @@ +set(PXR_PREFIX pxr/usd) +set(PXR_PACKAGE usdText) + +pxr_library(usdText + LIBRARIES + tf + usd + usdGeom + + PUBLIC_CLASSES + textStyleAPI + textStyle + simpleText + tokens + + PUBLIC_HEADERS + api.h + + PYTHON_CPPFILES + moduleDeps.cpp + + PYMODULE_CPPFILES + module.cpp + wrapTextStyleAPI.cpp + wrapTextStyle.cpp + wrapSimpleText.cpp + wrapTokens.cpp + ${optionalPyModuleFiles} + + PYMODULE_FILES + __init__.py + + RESOURCE_FILES + plugInfo.json + generatedSchema.usda + schema.usda:usdText/schema.usda +) + +pxr_test_scripts( + testenv/testUsdTextSimpleText.py + testenv/testUsdTextSchemata.py +) + +pxr_install_test_dir( + SRC testenv/testUsdTextSimpleText + DEST testUsdTextSimpleText +) + +pxr_register_test(testUsdTextSchemata + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdTextSchemata" + EXPECTED_RETURN_CODE 0 +) + +pxr_register_test(testUsdTextSimpleText + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdTextSimpleText" + EXPECTED_RETURN_CODE 0 +) \ No newline at end of file diff --git a/pxr/usd/usdText/__init__.py b/pxr/usd/usdText/__init__.py new file mode 100644 index 0000000000..0e22ea6ed1 --- /dev/null +++ b/pxr/usd/usdText/__init__.py @@ -0,0 +1,26 @@ +# +# Copyright 2024 Pixar +# +# Licensed under the Apache License, Version 2.0 (the "Apache License") +# with the following modification; you may not use this file except in +# compliance with the Apache License and the following modification to it: +# Section 6. Trademarks. is deleted and replaced with: +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor +# and its affiliates, except as required to comply with Section 4(c) of +# the License and to reproduce the content of the NOTICE file. +# +# You may obtain a copy of the Apache License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the Apache License with the above modification is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the Apache License for the specific +# language governing permissions and limitations under the Apache License. +# +from pxr import Tf +Tf.PreparePythonModule() +del Tf diff --git a/pxr/usd/usdText/api.h b/pxr/usd/usdText/api.h new file mode 100644 index 0000000000..b849ae9972 --- /dev/null +++ b/pxr/usd/usdText/api.h @@ -0,0 +1,30 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDTEXT_API_H +#define USDTEXT_API_H + +#include "pxr/base/arch/export.h" + +#if defined(PXR_STATIC) +# define USDTEXT_API +# define USDTEXT_API_TEMPLATE_CLASS(...) +# define USDTEXT_API_TEMPLATE_STRUCT(...) +# define USDTEXT_LOCAL +#else +# if defined(USDTEXT_EXPORTS) +# define USDTEXT_API ARCH_EXPORT +# define USDTEXT_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__) +# define USDTEXT_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__) +# else +# define USDTEXT_API ARCH_IMPORT +# define USDTEXT_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__) +# define USDTEXT_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__) +# endif +# define USDTEXT_LOCAL ARCH_HIDDEN +#endif + +#endif diff --git a/pxr/usd/usdText/generatedSchema.usda b/pxr/usd/usdText/generatedSchema.usda new file mode 100644 index 0000000000..c927928bee --- /dev/null +++ b/pxr/usd/usdText/generatedSchema.usda @@ -0,0 +1,247 @@ +#usda 1.0 +( + "WARNING: THIS FILE IS GENERATED BY usdGenSchema. DO NOT EDIT." +) + +class TextStyle "TextStyle" ( + doc = "This class includes the properties of the font and character." +) +{ + uniform int charHeight ( + doc = "The height of the character." + ) + uniform float charSpacingFactor = 1 ( + doc = "The factor how the character space is enlarged." + ) + uniform float charWidthFactor = 1 ( + doc = """The factor how a character's width is enlarged. If the width of a normal character is 1.0, and this + factor is 0.5, the final width of the character will be 0.5.""" + ) + uniform string font:altFormat = "none" ( + allowedTokens = ["none", "ttf/cff/otf", "fon", "pcf", "shx", "pfa/pfb", "bdf"] + doc = '''The font format for the alternate typeface. When this value is "none", it means the font format + is the default format. User can define the default format. For example, on Windows you can define the default + format is "ttf/cff/otf".''' + ) + uniform string font:altTypeface ( + doc = "An alternate typeface. It will be used if the 'typeface' is not available in the system." + ) + uniform bool font:bold = 0 ( + doc = "Whether the font style contains bold style. It is valid only when font:weight is zero or negative." + ) + uniform string font:format = "none" ( + allowedTokens = ["none", "ttf/cff/otf", "fon", "pcf", "shx", "pfa/pfb", "bdf"] + doc = '''The font format. When this value is "none", it means the font format is the default format. User + can define the default format. For example, on Windows you can define the default format is "ttf/cff/otf".''' + ) + uniform bool font:italic = 0 ( + doc = "Whether the font style contains italic style." + ) + uniform string font:typeface ( + doc = "The typeface of the font." + ) + uniform int font:weight = 0 ( + doc = """The weight of the stroke. If it is zero or negative, it means this property is ignored. Otherwise, + the definition of the weight value is the same as the definition of weight in CSS. + + This is how the weight is mapped to a font style in CSS. + weight value | font style + -------------- | ----------- + 100 | Thin + 200 | Extra Light + 300 | Light + 400 | Normal(Regular) + 500 | Medium + 600 | Semi Bold + 700 | Bold + 800 | Extra Bold + 900 | Ultra Bold + + If the value is not in the table, we will find a nearest value in the table, and the style will be the + corresponding font style. + """ + ) + uniform float obliqueAngle = 0 ( + doc = """The slant angle of the character. It is often achieved by applying a skew matrix to the original + character.""" + ) + uniform string overlineType = "none" ( + allowedTokens = ["none", "normal"] + doc = "The type of overline." + ) + uniform string strikethroughType = "none" ( + allowedTokens = ["none", "normal", "doubleLines"] + doc = "The type of strikethrough." + ) + uniform string underlineType = "none" ( + allowedTokens = ["none", "normal"] + doc = "The type of underline." + ) +} + +class "TextStyleAPI" ( + doc = """UsdTextTextStyleAPI is an API schema that provides an interface for binding text style to a text + primitive.""" +) +{ +} + +class "TextLayoutAPI" ( + doc = """UsdTextTextLayoutAPI is an API schema that provides an interface for setting the layout of a text + primitive.""" +) +{ + uniform token layout:baselineDirection = "upToImpl" ( + allowedTokens = ["upToImpl", "leftToRight", "rightToLeft", "topToBottom", "bottomToTop"] + doc = "The direction of the baseline." + ) + uniform token layout:linesStackDirection = "upToImpl" ( + allowedTokens = ["upToImpl", "leftToRight", "rightToLeft", "topToBottom", "bottomToTop"] + doc = """The direction of the line stacking. + If layout:baselineDirection is 'leftToRight' or 'rightToLeft', the layout:linesStackDirection can not be + 'leftToRight' or 'rightToLeft'. If layout:baselineDirection is 'topToBottom' or 'bottomToTop', the + layout:linesStackDirection can not be 'topToBottom' or 'bottomToTop'.""" + ) +} + +class SimpleText "SimpleText" ( + doc = """Class for single line single style text. + 'Single line' means that the baseline of the characters is straight and there is no line break. + 'Single style' means the appearance style for the characters are assumed to be the same. Here, + we use 'assume' because the user would like that the style is the same, but in the implementation, + a part of the characters may not be supported so it may use an alternate style to display the + characters. That is, although in schema level we use one text style for the SimpleText, on the + screen some characters may still be rendered with a different style.""" +) +{ + uniform bool doubleSided = 0 ( + doc = """Although some renderers treat all parametric or polygonal + surfaces as if they were effectively laminae with outward-facing + normals on both sides, some renderers derive significant optimizations + by considering these surfaces to have only a single outward side, + typically determined by control-point winding order and/or + orientation. By doing so they can perform \"backface culling\" to + avoid drawing the many polygons of most closed surfaces that face away + from the viewer. + + However, it is often advantageous to model thin objects such as paper + and cloth as single, open surfaces that must be viewable from both + sides, always. Setting a gprim's doubleSided attribute to + \\c true instructs all renderers to disable optimizations such as + backface culling for the gprim, and attempt (not all renderers are able + to do so, but the USD reference GL renderer always will) to provide + forward-facing normals on each side of the surface for lighting + calculations.""" + ) + float3[] extent ( + doc = """Extent is a three dimensional range measuring the geometric + extent of the authored gprim in its own local space (i.e. its own + transform not applied), without accounting for any shader-induced + displacement. If __any__ extent value has been authored for a given + Boundable, then it should be authored at every timeSample at which + geometry-affecting properties are authored, to ensure correct + evaluation via ComputeExtent(). If __no__ extent value has been + authored, then ComputeExtent() will call the Boundable's registered + ComputeExtentFunction(), which may be expensive, which is why we + strongly encourage proper authoring of extent. + \\sa ComputeExtent() + \\sa \\ref UsdGeom_Boundable_Extent. + + An authored extent on a prim which has children is expected to include + the extent of all children, as they will be pruned from BBox computation + during traversal.""" + ) + uniform token orientation = "rightHanded" ( + allowedTokens = ["rightHanded", "leftHanded"] + doc = """Orientation specifies whether the gprim's surface normal + should be computed using the right hand rule, or the left hand rule. + Please see for a deeper explanation and + generalization of orientation to composed scenes with transformation + hierarchies.""" + ) + uniform color3f primvars:backgroundColor ( + doc = "Background color for the text." + ) + uniform float primvars:backgroundOpacity = 0 ( + doc = "Background opacity for the text." + ) + color3f[] primvars:displayColor ( + doc = '''It is useful to have an "official" colorSet that can be used + as a display or modeling color, even in the absence of any specified + shader for a gprim. DisplayColor serves this role; because it is a + UsdGeomPrimvar, it can also be used as a gprim override for any shader + that consumes a displayColor parameter.''' + ) + float[] primvars:displayOpacity ( + doc = """Companion to displayColor that specifies opacity, broken + out as an independent attribute rather than an rgba color, both so that + each can be independently overridden, and because shaders rarely consume + rgba parameters.""" + ) + rel proxyPrim ( + doc = '''The proxyPrim relationship allows us to link a + prim whose purpose is "render" to its (single target) + purpose="proxy" prim. This is entirely optional, but can be + useful in several scenarios: + + - In a pipeline that does pruning (for complexity management) + by deactivating prims composed from asset references, when we + deactivate a purpose="render" prim, we will be able to discover + and additionally deactivate its associated purpose="proxy" prim, + so that preview renders reflect the pruning accurately. + + - DCC importers may be able to make more aggressive optimizations + for interactive processing and display if they can discover the proxy + for a given render prim. + + - With a little more work, a Hydra-based application will be able + to map a picked proxy prim back to its render geometry for selection. + + \\note It is only valid to author the proxyPrim relationship on + prims whose purpose is "render".''' + ) + uniform token purpose = "default" ( + allowedTokens = ["default", "render", "proxy", "guide"] + doc = """Purpose is a classification of geometry into categories that + can each be independently included or excluded from traversals of prims + on a stage, such as rendering or bounding-box computation traversals. + + See for more detail about how + purpose is computed and used.""" + ) + uniform string textData ( + doc = "The text string data." + ) + uniform token textMetricsUnit = "worldUnit" ( + allowedTokens = ["worldUnit", "publishingPoint", "pixel"] + doc = """The unit for the text related metrics, such as the unit of charHeight. + If the value is 'pixel', the unit of text metrics will be the same as a pixel in the framebuffer. + If the value is 'publishingPoint', the unit will be the same as desktop publishing point, or 1/72 + of an inch on a screen's physical display. If textMetricsUnit is 'worldUnit'\", the unit will be + the same as the unit of the world space. + If the text primitive has billboard, the textMetricsUnit can only be 'pixel' or 'publishingPoint'. + Otherwise, the textMetricsUnit can only be 'worldUnit'. + """ + ) + token visibility = "inherited" ( + allowedTokens = ["inherited", "invisible"] + doc = '''Visibility is meant to be the simplest form of "pruning" + visibility that is supported by most DCC apps. Visibility is + animatable, allowing a sub-tree of geometry to be present for some + segment of a shot, and absent from others; unlike the action of + deactivating geometry prims, invisible geometry is still + available for inspection, for positioning, for defining volumes, etc.''' + ) + uniform token[] xformOpOrder ( + doc = """Encodes the sequence of transformation operations in the + order in which they should be pushed onto a transform stack while + visiting a UsdStage's prims in a graph traversal that will effect + the desired positioning for this prim and its descendant prims. + + You should rarely, if ever, need to manipulate this attribute directly. + It is managed by the AddXformOp(), SetResetXformStack(), and + SetXformOpOrder(), and consulted by GetOrderedXformOps() and + GetLocalTransformation().""" + ) +} + diff --git a/pxr/usd/usdText/module.cpp b/pxr/usd/usdText/module.cpp new file mode 100644 index 0000000000..c7c9f2967a --- /dev/null +++ b/pxr/usd/usdText/module.cpp @@ -0,0 +1,35 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/pxr.h" +#include "pxr/base/tf/pyModule.h" + +PXR_NAMESPACE_USING_DIRECTIVE + +TF_WRAP_MODULE +{ + TF_WRAP(UsdTextTextStyle); + TF_WRAP(UsdTextTextStyleAPI); + TF_WRAP(UsdTextTokens); + TF_WRAP(UsdTextSimpleText); +} diff --git a/pxr/usd/usdText/moduleDeps.cpp b/pxr/usd/usdText/moduleDeps.cpp new file mode 100644 index 0000000000..102d719cfa --- /dev/null +++ b/pxr/usd/usdText/moduleDeps.cpp @@ -0,0 +1,46 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +//////////////////////////////////////////////////////////////////////// + +#include "pxr/pxr.h" +#include "pxr/base/tf/registryManager.h" +#include "pxr/base/tf/scriptModuleLoader.h" +#include "pxr/base/tf/token.h" + +PXR_NAMESPACE_OPEN_SCOPE + +TF_REGISTRY_FUNCTION(TfScriptModuleLoader) { + // List of direct dependencies for this library. + const std::vector reqs = { + TfToken("tf"), + TfToken("usd"), + TfToken("usdGeom") + }; + TfScriptModuleLoader::GetInstance(). + RegisterLibrary(TfToken("usdText"), TfToken("pxr.UsdText"), reqs); +} + +PXR_NAMESPACE_CLOSE_SCOPE + + diff --git a/pxr/usd/usdText/pch.h b/pxr/usd/usdText/pch.h new file mode 100644 index 0000000000..3e061a1b7a --- /dev/null +++ b/pxr/usd/usdText/pch.h @@ -0,0 +1,107 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +// WARNING: THIS FILE IS GENERATED. DO NOT EDIT. +// + +#define TF_MAX_ARITY 7 +#include "pxr/pxr.h" +#include "pxr/base/arch/defines.h" +#if defined(ARCH_OS_DARWIN) +#include +#endif +#if defined(ARCH_OS_LINUX) +#include +#endif +#if defined(ARCH_OS_WINDOWS) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef PXR_PYTHON_SUPPORT_ENABLED +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(__APPLE__) // Fix breakage caused by Python's pyport.h. +#undef tolower +#undef toupper +#endif +#endif // PXR_PYTHON_SUPPORT_ENABLED +#include +#ifdef PXR_PYTHON_SUPPORT_ENABLED +#include "pxr/base/tf/pySafePython.h" +#endif // PXR_PYTHON_SUPPORT_ENABLED diff --git a/pxr/usd/usdText/plugInfo.json b/pxr/usd/usdText/plugInfo.json new file mode 100644 index 0000000000..204589b7e7 --- /dev/null +++ b/pxr/usd/usdText/plugInfo.json @@ -0,0 +1,59 @@ +# Portions of this file auto-generated by usdGenSchema. +# Edits will survive regeneration except for comments and +# changes to types with autoGenerated=true. +{ + "Plugins": [ + { + "Info": { + "Types": { + "UsdTextSimpleText": { + "alias": { + "UsdSchemaBase": "SimpleText" + }, + "autoGenerated": true, + "bases": [ + "UsdGeomGprim" + ], + "implementsComputeExtent": true, + "schemaKind": "concreteTyped" + }, + "UsdTextTextLayoutAPI": { + "alias": { + "UsdSchemaBase": "TextLayoutAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, + "UsdTextTextStyle": { + "alias": { + "UsdSchemaBase": "TextStyle" + }, + "autoGenerated": true, + "bases": [ + "UsdTyped" + ], + "schemaKind": "concreteTyped" + }, + "UsdTextTextStyleAPI": { + "alias": { + "UsdSchemaBase": "TextStyleAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + } + } + }, + "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@", + "Name": "usdText", + "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@", + "Root": "@PLUG_INFO_ROOT@", + "Type": "library" + } + ] +} diff --git a/pxr/usd/usdText/schema.usda b/pxr/usd/usdText/schema.usda new file mode 100644 index 0000000000..1dedbfc52c --- /dev/null +++ b/pxr/usd/usdText/schema.usda @@ -0,0 +1,220 @@ +#usda 1.0 +( + "This file describes the USD Text schemata for code generation." + subLayers = [ + @usd/schema.usda@, + @usdGeom/schema.usda@ + ] +) + +over "GLOBAL" ( + customData = { + string libraryName = "usdText" + string libraryPath = "pxr/usd/usdText" + dictionary libraryTokens = { + } + } +) +{ +} + + +class TextStyle "TextStyle" ( + inherits = + doc = """This class includes the properties of the font and character.""" + customData = { + string extraIncludes =""" +#include + """ + } +) { + uniform string font:typeface ( + doc = """The typeface of the font.""" + ) + + uniform string font:format = "none" ( + allowedTokens = ["none", "ttf/cff/otf", "fon", "pcf", "shx", "pfa/pfb", "bdf"] + doc = """The font format. When this value is \"none\", it means the font format is the default format. User + can define the default format. For example, on Windows you can define the default format is \"ttf/cff/otf\".""" + ) + + uniform string font:altTypeface ( + doc = """An alternate typeface. It will be used if the 'typeface' is not available in the system.""" + ) + + uniform string font:altFormat = "none" ( + allowedTokens = ["none", "ttf/cff/otf", "fon", "pcf", "shx", "pfa/pfb", "bdf"] + doc = """The font format for the alternate typeface. When this value is \"none\", it means the font format + is the default format. User can define the default format. For example, on Windows you can define the default + format is \"ttf/cff/otf\".""" + ) + + uniform bool font:bold = false ( + doc = """Whether the font style contains bold style. It is valid only when font:weight is zero or negative.""" + ) + + uniform bool font:italic = false ( + doc = """Whether the font style contains italic style.""" + ) + + uniform int font:weight = 0 ( + doc = """The weight of the stroke. If it is zero or negative, it means this property is ignored. Otherwise, + the definition of the weight value is the same as the definition of weight in CSS. + + This is how the weight is mapped to a font style in CSS. + weight value | font style + -------------- | ----------- + 100 | Thin + 200 | Extra Light + 300 | Light + 400 | Normal(Regular) + 500 | Medium + 600 | Semi Bold + 700 | Bold + 800 | Extra Bold + 900 | Ultra Bold + + If the value is not in the table, we will find a nearest value in the table, and the style will be the + corresponding font style. + """ + ) + + uniform int charHeight ( + doc = """The height of the character.""" + ) + + uniform float charWidthFactor = 1.0 ( + doc = """The factor how a character's width is enlarged. If the width of a normal character is 1.0, and this + factor is 0.5, the final width of the character will be 0.5.""" + ) + + #obliqueAngle + uniform float obliqueAngle = 0.0 ( + doc = """The slant angle of the character. It is often achieved by applying a skew matrix to the original + character.""" + ) + + #Charspacing + uniform float charSpacingFactor = 1.0 ( + doc = """The factor how the character space is enlarged.""" + ) + + #UnderlineType + uniform string underlineType = "none" ( + allowedTokens = ["none", "normal"] + doc = """The type of underline.""" + ) + + #OverlineType + uniform string overlineType = "none" ( + allowedTokens = ["none", "normal"] + doc = """The type of overline.""" + ) + + #StrikethroughType + uniform string strikethroughType = "none" ( + allowedTokens = ["none", "normal", "doubleLines"] + doc = """The type of strikethrough.""" + ) +} + +class "TextStyleAPI" +( + inherits = + doc = """UsdTextTextStyleAPI is an API schema that provides an interface for binding text style to a text + primitive.""" + customData = { + string extraIncludes = """ +#include "pxr/usd/usdText/textStyle.h" +#include + """ + token apiSchemaType = "singleApply" + dictionary schemaTokens = { + dictionary textStyleBinding = { + string value = "textStyle:binding" + string doc = """ + The relationship name to denote a binding to a UsdTextTextStyle. + """ + } + } + } +) { +} + +class "TextLayoutAPI" ( + inherits = + doc = """UsdTextTextLayoutAPI is an API schema that provides an interface for setting the layout of a text + primitive.""" + customData = { + string extraIncludes =""" +#include + """ + token apiSchemaType = "singleApply" + } +) { + uniform token layout:baselineDirection = "upToImpl" ( + allowedTokens = ["upToImpl", "leftToRight", "rightToLeft", "topToBottom", "bottomToTop"] + doc = """The direction of the baseline.""" + ) + + uniform token layout:linesStackDirection = "upToImpl" ( + allowedTokens = ["upToImpl", "leftToRight", "rightToLeft", "topToBottom", "bottomToTop"] + doc = """The direction of the line stacking. + If layout:baselineDirection is 'leftToRight' or 'rightToLeft', the layout:linesStackDirection can not be + 'leftToRight' or 'rightToLeft'. If layout:baselineDirection is 'topToBottom' or 'bottomToTop', the + layout:linesStackDirection can not be 'topToBottom' or 'bottomToTop'.""" + ) +} + +class SimpleText "SimpleText" ( + doc = """Class for single line single style text. + 'Single line' means that the baseline of the characters is straight and there is no line break. + 'Single style' means the appearance style for the characters are assumed to be the same. Here, + we use 'assume' because the user would like that the style is the same, but in the implementation, + a part of the characters may not be supported so it may use an alternate style to display the + characters. That is, although in schema level we use one text style for the SimpleText, on the + screen some characters may still be rendered with a different style.""" + + inherits = + customData = { + dictionary extraPlugInfo = { + bool implementsComputeExtent = true + } + string extraIncludes =""" +#include +#include "pxr/usd/usdText/textStyle.h" + """ + } +) { + # textData + uniform string textData ( + doc = """The text string data.""" + ) + + uniform color3f primvars:backgroundColor ( + customData = { + string apiName = "backgroundColor" + } + doc = """Background color for the text.""" + ) + uniform float primvars:backgroundOpacity = 0.0 ( + customData = { + string apiName = "backgroundOpacity" + } + doc = """Background opacity for the text.""" + ) + uniform token textMetricsUnit = "worldUnit" ( + customData = { + string apiName = "textMetricsUnit" + } + allowedTokens = ["worldUnit", "publishingPoint", "pixel"] + doc = """The unit for the text related metrics, such as the unit of charHeight. + If the value is 'pixel', the unit of text metrics will be the same as a pixel in the framebuffer. + If the value is 'publishingPoint', the unit will be the same as desktop publishing point, or 1/72 + of an inch on a screen's physical display. If textMetricsUnit is 'worldUnit'", the unit will be + the same as the unit of the world space. + If the text primitive has billboard, the textMetricsUnit can only be 'pixel' or 'publishingPoint'. + Otherwise, the textMetricsUnit can only be 'worldUnit'. + """ + ) +} diff --git a/pxr/usd/usdText/simpleText.cpp b/pxr/usd/usdText/simpleText.cpp new file mode 100644 index 0000000000..9fc17c1ff9 --- /dev/null +++ b/pxr/usd/usdText/simpleText.cpp @@ -0,0 +1,234 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/simpleText.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + + // Register the usd prim typename as an alias under UsdSchemaBase. This + // enables one to call + // TfType::Find().FindDerivedByName("SimpleText") + // to find TfType, which is how IsA queries are + // answered. + TfType::AddAlias("SimpleText"); +} + +/* virtual */ +UsdTextSimpleText::~UsdTextSimpleText() +{ +} + +/* static */ +UsdTextSimpleText +UsdTextSimpleText::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextSimpleText(); + } + return UsdTextSimpleText(stage->GetPrimAtPath(path)); +} + +/* static */ +UsdTextSimpleText +UsdTextSimpleText::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("SimpleText"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextSimpleText(); + } + return UsdTextSimpleText( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind UsdTextSimpleText::_GetSchemaKind() const +{ + return UsdTextSimpleText::schemaKind; +} + +/* static */ +const TfType & +UsdTextSimpleText::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdTextSimpleText::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdTextSimpleText::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdTextSimpleText::GetTextDataAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->textData); +} + +UsdAttribute +UsdTextSimpleText::CreateTextDataAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->textData, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextSimpleText::GetBackgroundColorAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->primvarsBackgroundColor); +} + +UsdAttribute +UsdTextSimpleText::CreateBackgroundColorAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->primvarsBackgroundColor, + SdfValueTypeNames->Color3f, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextSimpleText::GetBackgroundOpacityAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->primvarsBackgroundOpacity); +} + +UsdAttribute +UsdTextSimpleText::CreateBackgroundOpacityAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->primvarsBackgroundOpacity, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextSimpleText::GetTextMetricsUnitAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->textMetricsUnit); +} + +UsdAttribute +UsdTextSimpleText::CreateTextMetricsUnitAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->textMetricsUnit, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +UsdTextSimpleText::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdTextTokens->textData, + UsdTextTokens->primvarsBackgroundColor, + UsdTextTokens->primvarsBackgroundOpacity, + UsdTextTokens->textMetricsUnit, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdGeomGprim::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +#include "pxr/usd/usdGeom/boundableComputeExtent.h" +#include "pxr/base/tf/registryManager.h" +#include "pxr/usd/usdGeom/pointBased.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// A temporary function to calculate the extent for the simpleText. The extent is hardcoded to +// [0.0, -500.0, 500.0, 0.0]. This calculation need to be rewrite after the simpleText is moved +// to usdText project. +static bool +_ComputeExtentForSimpleText( + const UsdGeomBoundable& boundable, + const UsdTimeCode& time, + const GfMatrix4d* transform, + VtVec3fArray* extent) +{ + const UsdTextSimpleText simpleText(boundable); + if (!TF_VERIFY(simpleText)) { + return false; + } + + extent->resize(2); + (*extent)[0] = GfVec3f(0.0f, -500.0f, -1.0f); + (*extent)[1] = GfVec3f(500.0f, 0.0f, 1.0f); + return true; +} + +TF_REGISTRY_FUNCTION(UsdGeomBoundable) +{ + UsdGeomRegisterComputeExtentFunction( + _ComputeExtentForSimpleText); +} + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdText/simpleText.h b/pxr/usd/usdText/simpleText.h new file mode 100644 index 0000000000..45f091f3e5 --- /dev/null +++ b/pxr/usd/usdText/simpleText.h @@ -0,0 +1,264 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDTEXT_GENERATED_SIMPLETEXT_H +#define USDTEXT_GENERATED_SIMPLETEXT_H + +/// \file usdText/simpleText.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/usd/usdGeom/gprim.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdText/tokens.h" + +#include +#include "pxr/usd/usdText/textStyle.h" + + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// SIMPLETEXT // +// -------------------------------------------------------------------------- // + +/// \class UsdTextSimpleText +/// +/// Class for single line single style text. +/// 'Single line' means that the baseline of the characters is straight and there is no line break. +/// 'Single style' means the appearance style for the characters are assumed to be the same. Here, +/// we use 'assume' because the user would like that the style is the same, but in the implementation, +/// a part of the characters may not be supported so it may use an alternate style to display the +/// characters. That is, although in schema level we use one text style for the SimpleText, on the +/// screen some characters may still be rendered with a different style. +/// +/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below +/// that are text/tokens, the actual token is published and defined in \ref UsdTextTokens. +/// So to set an attribute to the value "rightHanded", use UsdTextTokens->rightHanded +/// as the value. +/// +class UsdTextSimpleText : public UsdGeomGprim +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a UsdTextSimpleText on UsdPrim \p prim . + /// Equivalent to UsdTextSimpleText::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdTextSimpleText(const UsdPrim& prim=UsdPrim()) + : UsdGeomGprim(prim) + { + } + + /// Construct a UsdTextSimpleText on the prim held by \p schemaObj . + /// Should be preferred over UsdTextSimpleText(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdTextSimpleText(const UsdSchemaBase& schemaObj) + : UsdGeomGprim(schemaObj) + { + } + + /// Destructor. + USDTEXT_API + virtual ~UsdTextSimpleText(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDTEXT_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdTextSimpleText holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// UsdTextSimpleText(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDTEXT_API + static UsdTextSimpleText + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + USDTEXT_API + static UsdTextSimpleText + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDTEXT_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDTEXT_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDTEXT_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // TEXTDATA + // --------------------------------------------------------------------- // + /// The text string data. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string textData` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetTextDataAttr() const; + + /// See GetTextDataAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateTextDataAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // BACKGROUNDCOLOR + // --------------------------------------------------------------------- // + /// Background color for the text. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform color3f primvars:backgroundColor` | + /// | C++ Type | GfVec3f | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Color3f | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetBackgroundColorAttr() const; + + /// See GetBackgroundColorAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateBackgroundColorAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // BACKGROUNDOPACITY + // --------------------------------------------------------------------- // + /// Background opacity for the text. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform float primvars:backgroundOpacity = 0` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetBackgroundOpacityAttr() const; + + /// See GetBackgroundOpacityAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateBackgroundOpacityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // TEXTMETRICSUNIT + // --------------------------------------------------------------------- // + /// The unit for the text related metrics, such as the unit of charHeight. + /// If the value is 'pixel', the unit of text metrics will be the same as a pixel in the framebuffer. + /// If the value is 'publishingPoint', the unit will be the same as desktop publishing point, or 1/72 + /// of an inch on a screen's physical display. If textMetricsUnit is 'worldUnit'", the unit will be + /// the same as the unit of the world space. + /// If the text primitive has billboard, the textMetricsUnit can only be 'pixel' or 'publishingPoint'. + /// Otherwise, the textMetricsUnit can only be 'worldUnit'. + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform token textMetricsUnit = "worldUnit"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | worldUnit, publishingPoint, pixel | + USDTEXT_API + UsdAttribute GetTextMetricsUnitAttr() const; + + /// See GetTextMetricsUnitAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateTextMetricsUnitAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdText/testenv/testUsdTextSchemata.py b/pxr/usd/usdText/testenv/testUsdTextSchemata.py new file mode 100644 index 0000000000..09833d1120 --- /dev/null +++ b/pxr/usd/usdText/testenv/testUsdTextSchemata.py @@ -0,0 +1,54 @@ +#!/pxrpythonsubst +# +# Copyright 2023 Pixar +# +# Licensed under the Apache License, Version 2.0 (the "Apache License") +# with the following modification; you may not use this file except in +# compliance with the Apache License and the following modification to it: +# Section 6. Trademarks. is deleted and replaced with: +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor +# and its affiliates, except as required to comply with Section 4(c) of +# the License and to reproduce the content of the NOTICE file. +# +# You may obtain a copy of the Apache License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the Apache License with the above modification is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the Apache License for the specific +# language governing permissions and limitations under the Apache License. + +# pylint: disable=map-builtin-not-iterating + +import sys, unittest +from pxr import Sdf, Usd, UsdGeom, UsdText, Vt, Gf, Tf + +class TestUsdTextSchemata(unittest.TestCase): + def test_IsA(self): + + # Author Scene and Compose Stage + + l = Sdf.Layer.CreateAnonymous() + stage = Usd.Stage.Open(l.identifier) + + # For every prim schema type in this module, validate that: + # 1. We can define a prim of its type + # 2. Its type and inheritance matches our expectations + # 3. At least one of its builtin properties is available and defined + + # SimpleText Tests + + schema = UsdText.SimpleText.Define(stage, "/SimpleText") + self.assertTrue(schema) + prim = schema.GetPrim() + self.assertFalse(prim.IsA(UsdGeom.Mesh)) # SimpleText is not a Mesh + self.assertTrue(prim.IsA(UsdGeom.Xformable)) # SimpleText is a Xformable + self.assertFalse(prim.IsA(UsdGeom.Cylinder)) # SimpleText is not a Cylinder + self.assertTrue(schema.GetTextDataAttr()) + +if __name__ == "__main__": + unittest.main() diff --git a/pxr/usd/usdText/testenv/testUsdTextSimpleText.py b/pxr/usd/usdText/testenv/testUsdTextSimpleText.py new file mode 100644 index 0000000000..1ca421cb57 --- /dev/null +++ b/pxr/usd/usdText/testenv/testUsdTextSimpleText.py @@ -0,0 +1,137 @@ +#!/pxrpythonsubst +# +# Copyright 2023 Pixar +# +# Licensed under the Apache License, Version 2.0 (the "Apache License") +# with the following modification; you may not use this file except in +# compliance with the Apache License and the following modification to it: +# Section 6. Trademarks. is deleted and replaced with: +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor +# and its affiliates, except as required to comply with Section 4(c) of +# the License and to reproduce the content of the NOTICE file. +# +# You may obtain a copy of the Apache License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the Apache License with the above modification is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the Apache License for the specific +# language governing permissions and limitations under the Apache License. + +import unittest + +from pxr import Gf, Usd, UsdText, Sdf + +class TestUsdTextSimpleText(unittest.TestCase): + def setUp(self): + self.layer = Sdf.Layer.CreateAnonymous() + self.stage = Usd.Stage.Open(self.layer.identifier) + self.texts = self.stage.DefinePrim("/TestSimpleText", "SimpleText") + self.schema = UsdText.SimpleText(self.texts) + + def test_create(self): + assert self.texts + assert self.texts.GetName() == 'TestSimpleText' + + def test_schema(self): + assert self.schema + assert 'textData' in self.schema.GetSchemaAttributeNames() + assert 'primvars:backgroundColor' in self.schema.GetSchemaAttributeNames() + assert 'primvars:backgroundOpacity' in self.schema.GetSchemaAttributeNames() + assert 'textMetricsUnit' in self.schema.GetSchemaAttributeNames() + + def test_Attributes(self): + stage = Usd.Stage.Open('simpleText.usda') + time = Usd.TimeCode.Default() + schema = UsdText.SimpleText.Get(stage, '/TextA') + textData = schema.GetTextDataAttr().Get(time); + self.assertEqual(textData, 'The quick brown fox') + displayColor = schema.GetDisplayColorAttr().Get(time); + self.assertEqual(displayColor, [(1, 1, 0)]); + backgroundColor = schema.GetBackgroundColorAttr().Get(time); + self.assertEqual(backgroundColor, (0, 1, 0)); + backgroundOpacity = schema.GetBackgroundOpacityAttr().Get(time); + self.assertTrue(Gf.IsClose(backgroundOpacity, 0.78, 1e-6)); + textMetricsUnit = schema.GetTextMetricsUnitAttr().Get(time); + self.assertEqual(textMetricsUnit, UsdText.Tokens.publishingPoint); + + schema = UsdText.SimpleText.Get(stage, '/TextB') + textData = schema.GetTextDataAttr().Get(time); + self.assertEqual(textData, 'jumps over the') + displayColor = schema.GetDisplayColorAttr().Get(time); + self.assertEqual(displayColor, [(1, 0, 1)]); + schema.GetBackgroundColorAttr().Set((1, 0, 0)); + backGroundColor = schema.GetBackgroundColorAttr().Get(time); + self.assertEqual(backGroundColor, (1, 0, 0)); + schema.GetBackgroundOpacityAttr().Set(0.92); + backGroundOpacity = schema.GetBackgroundOpacityAttr().Get(time); + self.assertTrue(Gf.IsClose(backGroundOpacity, 0.92, 1e-6)); + schema.GetTextMetricsUnitAttr().Set(UsdText.Tokens.pixel); + textMetricsUnit = schema.GetTextMetricsUnitAttr().Get(time); + self.assertEqual(textMetricsUnit, UsdText.Tokens.pixel); + + def test_TextStyle(self): + stage = Usd.Stage.Open('simpleText.usda') + time = Usd.TimeCode.Default() + prim = stage.GetPrimAtPath('/TextA') + primPath = prim.GetPath() + textStyleAPI = UsdText.TextStyleAPI.Apply(prim); + if textStyleAPI.CanApply(prim): + textStyleBinding = textStyleAPI.GetTextStyleBinding(primPath); + style = textStyleBinding.GetTextStyle(); + typeface = style.GetFontTypefaceAttr().Get(time); + self.assertEqual(typeface, 'Times New Roman') + format = style.GetFontFormatAttr().Get(time); + self.assertEqual(format, 'ttf/cff/otf') + altTypeface = style.GetFontAltTypefaceAttr().Get(time); + self.assertEqual(altTypeface, 'Arial') + altFormat = style.GetFontAltFormatAttr().Get(time); + self.assertEqual(altFormat, 'ttf/cff/otf') + ifBold = style.GetFontBoldAttr().Get(time); + self.assertTrue(ifBold) + charHeight = style.GetCharHeightAttr().Get(time); + self.assertEqual(charHeight, 100) + charWidth = style.GetCharWidthFactorAttr().Get(time); + self.assertTrue(Gf.IsClose(charWidth, 1.2, 1e-6)); + charSpacingFactor = style.GetCharSpacingFactorAttr().Get(time); + self.assertTrue(Gf.IsClose(charSpacingFactor, 1.5, 1e-6)); + obliqueAngle = style.GetObliqueAngleAttr().Get(time); + self.assertTrue(Gf.IsClose(obliqueAngle, 0.8, 1e-6)); + overlineType = style.GetOverlineTypeAttr().Get(time); + self.assertEqual(overlineType, "normal") + prim = stage.GetPrimAtPath('/TextB') + primPath = prim.GetPath() + textStyleAPI = UsdText.TextStyleAPI.Apply(prim); + if textStyleAPI.CanApply(prim): + textStyleBinding = textStyleAPI.GetTextStyleBinding(primPath); + style = textStyleBinding.GetTextStyle(); + typeface = style.GetFontTypefaceAttr().Get(time); + self.assertEqual(typeface, 'Arial') + format = style.GetFontFormatAttr().Get(time); + self.assertEqual(format, 'none') + italic = style.GetFontItalicAttr().Get(time); + self.assertEqual(italic, 1) + weight = style.GetFontWeightAttr().Get(time); + self.assertEqual(weight, 300) + charHeight = style.GetCharHeightAttr().Get(time); + self.assertEqual(charHeight, 70) + style.GetCharWidthFactorAttr().Set(0.66); + charWidth = style.GetCharWidthFactorAttr().Get(time); + self.assertTrue(Gf.IsClose(charWidth, 0.66, 1e-6)); + style.GetObliqueAngleAttr().Set(1.22); + obliqueAngle = style.GetObliqueAngleAttr().Get(time); + self.assertTrue(Gf.IsClose(obliqueAngle, 1.22, 1e-6)); + style.GetOverlineTypeAttr().Set("normal"); + overlineType = style.GetOverlineTypeAttr().Get(time); + self.assertEqual(overlineType, "normal"); + underlineType = style.GetUnderlineTypeAttr().Get(time); + self.assertEqual(underlineType, "normal") + strikethroughType = style.GetStrikethroughTypeAttr().Get(time); + self.assertEqual(strikethroughType, "doubleLines") + +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/pxr/usd/usdText/testenv/testUsdTextSimpleText/simpleText.usda b/pxr/usd/usdText/testenv/testUsdTextSimpleText/simpleText.usda new file mode 100644 index 0000000000..b729d16e14 --- /dev/null +++ b/pxr/usd/usdText/testenv/testUsdTextSimpleText/simpleText.usda @@ -0,0 +1,48 @@ +#usda 1.0 + +def SimpleText "TextA" ( + prepend apiSchemas = ["TextStyleAPI"] +){ + uniform token[] xformOpOrder = ["xformOp:translate"] + float3 xformOp:translate = (-300, 60, 0) + + string textData = "The quick brown fox" + color3f[] primvars:displayColor = [(1, 1, 0)] + color3f primvars:backgroundColor = (0, 1, 0) + float primvars:backgroundOpacity = 0.78 + token textMetricsUnit = "publishingPoint" + rel textStyle:binding = +} +def SimpleText "TextB" ( + prepend apiSchemas = ["TextStyleAPI"] +){ + uniform token[] xformOpOrder = ["xformOp:translate"] + float3 xformOp:translate = (-300, -40, 0) + + string textData = "jumps over the" + color3f[] primvars:displayColor = [(1, 0, 1)] + rel textStyle:binding = +} + +def TextStyle "StyleA" { + string font:typeface = "Times New Roman" + string font:format = "ttf/cff/otf" + string font:altTypeface = "Arial" + string font:altFormat = "ttf/cff/otf" + bool font:bold = 1 + int charHeight = 100 + float charWidthFactor = 1.2 + float charSpacingFactor = 1.5 + float obliqueAngle = 0.8 + string overlineType = "normal" +} + +def TextStyle "StyleB" { + string font:typeface = "Arial" + string font:format = "none" + int font:weight = 300 + bool font:italic = 1 + int charHeight = 70 + string underlineType = "normal" + string strikethroughType = "doubleLines" +} \ No newline at end of file diff --git a/pxr/usd/usdText/textLayoutAPI.cpp b/pxr/usd/usdText/textLayoutAPI.cpp new file mode 100644 index 0000000000..d95ff07415 --- /dev/null +++ b/pxr/usd/usdText/textLayoutAPI.cpp @@ -0,0 +1,162 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/textLayoutAPI.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + +} + +/* virtual */ +UsdTextTextLayoutAPI::~UsdTextTextLayoutAPI() +{ +} + +/* static */ +UsdTextTextLayoutAPI +UsdTextTextLayoutAPI::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextTextLayoutAPI(); + } + return UsdTextTextLayoutAPI(stage->GetPrimAtPath(path)); +} + + +/* virtual */ +UsdSchemaKind UsdTextTextLayoutAPI::_GetSchemaKind() const +{ + return UsdTextTextLayoutAPI::schemaKind; +} + +/* static */ +bool +UsdTextTextLayoutAPI::CanApply( + const UsdPrim &prim, std::string *whyNot) +{ + return prim.CanApplyAPI(whyNot); +} + +/* static */ +UsdTextTextLayoutAPI +UsdTextTextLayoutAPI::Apply(const UsdPrim &prim) +{ + if (prim.ApplyAPI()) { + return UsdTextTextLayoutAPI(prim); + } + return UsdTextTextLayoutAPI(); +} + +/* static */ +const TfType & +UsdTextTextLayoutAPI::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdTextTextLayoutAPI::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdTextTextLayoutAPI::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdTextTextLayoutAPI::GetLayoutBaselineDirectionAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->layoutBaselineDirection); +} + +UsdAttribute +UsdTextTextLayoutAPI::CreateLayoutBaselineDirectionAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->layoutBaselineDirection, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextLayoutAPI::GetLayoutLinesStackDirectionAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->layoutLinesStackDirection); +} + +UsdAttribute +UsdTextTextLayoutAPI::CreateLayoutLinesStackDirectionAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->layoutLinesStackDirection, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +UsdTextTextLayoutAPI::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdTextTokens->layoutBaselineDirection, + UsdTextTokens->layoutLinesStackDirection, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdAPISchemaBase::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- diff --git a/pxr/usd/usdText/textLayoutAPI.h b/pxr/usd/usdText/textLayoutAPI.h new file mode 100644 index 0000000000..a3d5469c84 --- /dev/null +++ b/pxr/usd/usdText/textLayoutAPI.h @@ -0,0 +1,223 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDTEXT_GENERATED_TEXTLAYOUTAPI_H +#define USDTEXT_GENERATED_TEXTLAYOUTAPI_H + +/// \file usdText/textLayoutAPI.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/usd/usd/apiSchemaBase.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdText/tokens.h" + +#include + + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// TEXTLAYOUTAPI // +// -------------------------------------------------------------------------- // + +/// \class UsdTextTextLayoutAPI +/// +/// UsdTextTextLayoutAPI is an API schema that provides an interface for setting the layout of a text +/// primitive. +/// +/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below +/// that are text/tokens, the actual token is published and defined in \ref UsdTextTokens. +/// So to set an attribute to the value "rightHanded", use UsdTextTokens->rightHanded +/// as the value. +/// +class UsdTextTextLayoutAPI : public UsdAPISchemaBase +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI; + + /// Construct a UsdTextTextLayoutAPI on UsdPrim \p prim . + /// Equivalent to UsdTextTextLayoutAPI::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdTextTextLayoutAPI(const UsdPrim& prim=UsdPrim()) + : UsdAPISchemaBase(prim) + { + } + + /// Construct a UsdTextTextLayoutAPI on the prim held by \p schemaObj . + /// Should be preferred over UsdTextTextLayoutAPI(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdTextTextLayoutAPI(const UsdSchemaBase& schemaObj) + : UsdAPISchemaBase(schemaObj) + { + } + + /// Destructor. + USDTEXT_API + virtual ~UsdTextTextLayoutAPI(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDTEXT_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdTextTextLayoutAPI holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// UsdTextTextLayoutAPI(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDTEXT_API + static UsdTextTextLayoutAPI + Get(const UsdStagePtr &stage, const SdfPath &path); + + + /// Returns true if this single-apply API schema can be applied to + /// the given \p prim. If this schema can not be a applied to the prim, + /// this returns false and, if provided, populates \p whyNot with the + /// reason it can not be applied. + /// + /// Note that if CanApply returns false, that does not necessarily imply + /// that calling Apply will fail. Callers are expected to call CanApply + /// before calling Apply if they want to ensure that it is valid to + /// apply a schema. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDTEXT_API + static bool + CanApply(const UsdPrim &prim, std::string *whyNot=nullptr); + + /// Applies this single-apply API schema to the given \p prim. + /// This information is stored by adding "TextLayoutAPI" to the + /// token-valued, listOp metadata \em apiSchemas on the prim. + /// + /// \return A valid UsdTextTextLayoutAPI object is returned upon success. + /// An invalid (or empty) UsdTextTextLayoutAPI object is returned upon + /// failure. See \ref UsdPrim::ApplyAPI() for conditions + /// resulting in failure. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDTEXT_API + static UsdTextTextLayoutAPI + Apply(const UsdPrim &prim); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDTEXT_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDTEXT_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDTEXT_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // LAYOUTBASELINEDIRECTION + // --------------------------------------------------------------------- // + /// The direction of the baseline. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform token layout:baselineDirection = "upToImpl"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | upToImpl, leftToRight, rightToLeft, topToBottom, bottomToTop | + USDTEXT_API + UsdAttribute GetLayoutBaselineDirectionAttr() const; + + /// See GetLayoutBaselineDirectionAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateLayoutBaselineDirectionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // LAYOUTLINESSTACKDIRECTION + // --------------------------------------------------------------------- // + /// The direction of the line stacking. + /// If layout:baselineDirection is 'leftToRight' or 'rightToLeft', the layout:linesStackDirection can not be + /// 'leftToRight' or 'rightToLeft'. If layout:baselineDirection is 'topToBottom' or 'bottomToTop', the + /// layout:linesStackDirection can not be 'topToBottom' or 'bottomToTop'. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform token layout:linesStackDirection = "upToImpl"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | upToImpl, leftToRight, rightToLeft, topToBottom, bottomToTop | + USDTEXT_API + UsdAttribute GetLayoutLinesStackDirectionAttr() const; + + /// See GetLayoutLinesStackDirectionAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateLayoutLinesStackDirectionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdText/textStyle.cpp b/pxr/usd/usdText/textStyle.cpp new file mode 100644 index 0000000000..76f46a0762 --- /dev/null +++ b/pxr/usd/usdText/textStyle.cpp @@ -0,0 +1,379 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/textStyle.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + + // Register the usd prim typename as an alias under UsdSchemaBase. This + // enables one to call + // TfType::Find().FindDerivedByName("TextStyle") + // to find TfType, which is how IsA queries are + // answered. + TfType::AddAlias("TextStyle"); +} + +/* virtual */ +UsdTextTextStyle::~UsdTextTextStyle() +{ +} + +/* static */ +UsdTextTextStyle +UsdTextTextStyle::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextTextStyle(); + } + return UsdTextTextStyle(stage->GetPrimAtPath(path)); +} + +/* static */ +UsdTextTextStyle +UsdTextTextStyle::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("TextStyle"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextTextStyle(); + } + return UsdTextTextStyle( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind UsdTextTextStyle::_GetSchemaKind() const +{ + return UsdTextTextStyle::schemaKind; +} + +/* static */ +const TfType & +UsdTextTextStyle::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdTextTextStyle::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdTextTextStyle::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdTextTextStyle::GetFontTypefaceAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontTypeface); +} + +UsdAttribute +UsdTextTextStyle::CreateFontTypefaceAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontTypeface, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetFontFormatAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontFormat); +} + +UsdAttribute +UsdTextTextStyle::CreateFontFormatAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontFormat, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetFontAltTypefaceAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontAltTypeface); +} + +UsdAttribute +UsdTextTextStyle::CreateFontAltTypefaceAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontAltTypeface, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetFontAltFormatAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontAltFormat); +} + +UsdAttribute +UsdTextTextStyle::CreateFontAltFormatAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontAltFormat, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetFontBoldAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontBold); +} + +UsdAttribute +UsdTextTextStyle::CreateFontBoldAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontBold, + SdfValueTypeNames->Bool, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetFontItalicAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontItalic); +} + +UsdAttribute +UsdTextTextStyle::CreateFontItalicAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontItalic, + SdfValueTypeNames->Bool, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetFontWeightAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->fontWeight); +} + +UsdAttribute +UsdTextTextStyle::CreateFontWeightAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->fontWeight, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetCharHeightAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->charHeight); +} + +UsdAttribute +UsdTextTextStyle::CreateCharHeightAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->charHeight, + SdfValueTypeNames->Int, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetCharWidthFactorAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->charWidthFactor); +} + +UsdAttribute +UsdTextTextStyle::CreateCharWidthFactorAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->charWidthFactor, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetObliqueAngleAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->obliqueAngle); +} + +UsdAttribute +UsdTextTextStyle::CreateObliqueAngleAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->obliqueAngle, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetCharSpacingFactorAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->charSpacingFactor); +} + +UsdAttribute +UsdTextTextStyle::CreateCharSpacingFactorAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->charSpacingFactor, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetUnderlineTypeAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->underlineType); +} + +UsdAttribute +UsdTextTextStyle::CreateUnderlineTypeAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->underlineType, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetOverlineTypeAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->overlineType); +} + +UsdAttribute +UsdTextTextStyle::CreateOverlineTypeAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->overlineType, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextTextStyle::GetStrikethroughTypeAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->strikethroughType); +} + +UsdAttribute +UsdTextTextStyle::CreateStrikethroughTypeAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->strikethroughType, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +UsdTextTextStyle::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdTextTokens->fontTypeface, + UsdTextTokens->fontFormat, + UsdTextTokens->fontAltTypeface, + UsdTextTokens->fontAltFormat, + UsdTextTokens->fontBold, + UsdTextTokens->fontItalic, + UsdTextTokens->fontWeight, + UsdTextTokens->charHeight, + UsdTextTokens->charWidthFactor, + UsdTextTokens->obliqueAngle, + UsdTextTokens->charSpacingFactor, + UsdTextTokens->underlineType, + UsdTextTokens->overlineType, + UsdTextTokens->strikethroughType, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdTyped::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- diff --git a/pxr/usd/usdText/textStyle.h b/pxr/usd/usdText/textStyle.h new file mode 100644 index 0000000000..3a69ffa50d --- /dev/null +++ b/pxr/usd/usdText/textStyle.h @@ -0,0 +1,502 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDTEXT_GENERATED_TEXTSTYLE_H +#define USDTEXT_GENERATED_TEXTSTYLE_H + +/// \file usdText/textStyle.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/usd/usd/typed.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdText/tokens.h" + +#include + + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// TEXTSTYLE // +// -------------------------------------------------------------------------- // + +/// \class UsdTextTextStyle +/// +/// This class includes the properties of the font and character. +/// +class UsdTextTextStyle : public UsdTyped +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a UsdTextTextStyle on UsdPrim \p prim . + /// Equivalent to UsdTextTextStyle::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdTextTextStyle(const UsdPrim& prim=UsdPrim()) + : UsdTyped(prim) + { + } + + /// Construct a UsdTextTextStyle on the prim held by \p schemaObj . + /// Should be preferred over UsdTextTextStyle(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdTextTextStyle(const UsdSchemaBase& schemaObj) + : UsdTyped(schemaObj) + { + } + + /// Destructor. + USDTEXT_API + virtual ~UsdTextTextStyle(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDTEXT_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdTextTextStyle holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// UsdTextTextStyle(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDTEXT_API + static UsdTextTextStyle + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + USDTEXT_API + static UsdTextTextStyle + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDTEXT_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDTEXT_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDTEXT_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // FONTTYPEFACE + // --------------------------------------------------------------------- // + /// The typeface of the font. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string font:typeface` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetFontTypefaceAttr() const; + + /// See GetFontTypefaceAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontTypefaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // FONTFORMAT + // --------------------------------------------------------------------- // + /// The font format. When this value is "none", it means the font format is the default format. User + /// can define the default format. For example, on Windows you can define the default format is "ttf/cff/otf". + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string font:format = "none"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | none, ttf/cff/otf, fon, pcf, shx, pfa/pfb, bdf | + USDTEXT_API + UsdAttribute GetFontFormatAttr() const; + + /// See GetFontFormatAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontFormatAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // FONTALTTYPEFACE + // --------------------------------------------------------------------- // + /// An alternate typeface. It will be used if the 'typeface' is not available in the system. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string font:altTypeface` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetFontAltTypefaceAttr() const; + + /// See GetFontAltTypefaceAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontAltTypefaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // FONTALTFORMAT + // --------------------------------------------------------------------- // + /// The font format for the alternate typeface. When this value is "none", it means the font format + /// is the default format. User can define the default format. For example, on Windows you can define the default + /// format is "ttf/cff/otf". + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string font:altFormat = "none"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | none, ttf/cff/otf, fon, pcf, shx, pfa/pfb, bdf | + USDTEXT_API + UsdAttribute GetFontAltFormatAttr() const; + + /// See GetFontAltFormatAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontAltFormatAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // FONTBOLD + // --------------------------------------------------------------------- // + /// Whether the font style contains bold style. It is valid only when font:weight is zero or negative. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform bool font:bold = 0` | + /// | C++ Type | bool | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetFontBoldAttr() const; + + /// See GetFontBoldAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontBoldAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // FONTITALIC + // --------------------------------------------------------------------- // + /// Whether the font style contains italic style. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform bool font:italic = 0` | + /// | C++ Type | bool | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetFontItalicAttr() const; + + /// See GetFontItalicAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontItalicAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // FONTWEIGHT + // --------------------------------------------------------------------- // + /// The weight of the stroke. If it is zero or negative, it means this property is ignored. Otherwise, + /// the definition of the weight value is the same as the definition of weight in CSS. + /// + /// This is how the weight is mapped to a font style in CSS. + /// weight value | font style + /// -------------- | ----------- + /// 100 | Thin + /// 200 | Extra Light + /// 300 | Light + /// 400 | Normal(Regular) + /// 500 | Medium + /// 600 | Semi Bold + /// 700 | Bold + /// 800 | Extra Bold + /// 900 | Ultra Bold + /// + /// If the value is not in the table, we will find a nearest value in the table, and the style will be the + /// corresponding font style. + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform int font:weight = 0` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetFontWeightAttr() const; + + /// See GetFontWeightAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateFontWeightAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // CHARHEIGHT + // --------------------------------------------------------------------- // + /// The height of the character. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform int charHeight` | + /// | C++ Type | int | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetCharHeightAttr() const; + + /// See GetCharHeightAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateCharHeightAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // CHARWIDTHFACTOR + // --------------------------------------------------------------------- // + /// The factor how a character's width is enlarged. If the width of a normal character is 1.0, and this + /// factor is 0.5, the final width of the character will be 0.5. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform float charWidthFactor = 1` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetCharWidthFactorAttr() const; + + /// See GetCharWidthFactorAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateCharWidthFactorAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OBLIQUEANGLE + // --------------------------------------------------------------------- // + /// The slant angle of the character. It is often achieved by applying a skew matrix to the original + /// character. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform float obliqueAngle = 0` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetObliqueAngleAttr() const; + + /// See GetObliqueAngleAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateObliqueAngleAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // CHARSPACINGFACTOR + // --------------------------------------------------------------------- // + /// The factor how the character space is enlarged. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform float charSpacingFactor = 1` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDTEXT_API + UsdAttribute GetCharSpacingFactorAttr() const; + + /// See GetCharSpacingFactorAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateCharSpacingFactorAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // UNDERLINETYPE + // --------------------------------------------------------------------- // + /// The type of underline. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string underlineType = "none"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | none, normal | + USDTEXT_API + UsdAttribute GetUnderlineTypeAttr() const; + + /// See GetUnderlineTypeAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateUnderlineTypeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OVERLINETYPE + // --------------------------------------------------------------------- // + /// The type of overline. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string overlineType = "none"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | none, normal | + USDTEXT_API + UsdAttribute GetOverlineTypeAttr() const; + + /// See GetOverlineTypeAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateOverlineTypeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // STRIKETHROUGHTYPE + // --------------------------------------------------------------------- // + /// The type of strikethrough. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string strikethroughType = "none"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdTextTokens "Allowed Values" | none, normal, doubleLines | + USDTEXT_API + UsdAttribute GetStrikethroughTypeAttr() const; + + /// See GetStrikethroughTypeAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDTEXT_API + UsdAttribute CreateStrikethroughTypeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdText/textStyleAPI.cpp b/pxr/usd/usdText/textStyleAPI.cpp new file mode 100644 index 0000000000..144c57e74f --- /dev/null +++ b/pxr/usd/usdText/textStyleAPI.cpp @@ -0,0 +1,180 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/textStyleAPI.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + +} + +/* virtual */ +UsdTextTextStyleAPI::~UsdTextTextStyleAPI() +{ +} + +/* static */ +UsdTextTextStyleAPI +UsdTextTextStyleAPI::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextTextStyleAPI(); + } + return UsdTextTextStyleAPI(stage->GetPrimAtPath(path)); +} + + +/* virtual */ +UsdSchemaKind UsdTextTextStyleAPI::_GetSchemaKind() const +{ + return UsdTextTextStyleAPI::schemaKind; +} + +/* static */ +bool +UsdTextTextStyleAPI::CanApply( + const UsdPrim &prim, std::string *whyNot) +{ + return prim.CanApplyAPI(whyNot); +} + +/* static */ +UsdTextTextStyleAPI +UsdTextTextStyleAPI::Apply(const UsdPrim &prim) +{ + if (prim.ApplyAPI()) { + return UsdTextTextStyleAPI(prim); + } + return UsdTextTextStyleAPI(); +} + +/* static */ +const TfType & +UsdTextTextStyleAPI::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdTextTextStyleAPI::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdTextTextStyleAPI::_GetTfType() const +{ + return _GetStaticTfType(); +} + +/*static*/ +const TfTokenVector& +UsdTextTextStyleAPI::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames; + static TfTokenVector allNames = + UsdAPISchemaBase::GetSchemaAttributeNames(true); + + if (includeInherited) + return allNames; + else + return localNames; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- +PXR_NAMESPACE_OPEN_SCOPE +UsdRelationship +UsdTextTextStyleAPI::GetBindingRel() const +{ + return GetPrim().GetRelationship(UsdTextTokens->textStyleBinding); +} + +UsdTextTextStyleAPI::TextStyleBinding::TextStyleBinding( + const UsdRelationship &bindingRel, SdfPath const& textPrimPath) : + _bindingRel(bindingRel) +{ + // Get the textstyle path. + SdfPathVector targetPaths; + _bindingRel.GetForwardedTargets(&targetPaths); + if (targetPaths.size() == 1 && + targetPaths.front().IsPrimPath()) { + _textStylePath = targetPaths.front(); + } + + // Add a binding to the cache. + if (!_textStylePath.IsEmpty()) { + UsdTextTextStyleAPI::AddBindToCache(_textStylePath, textPrimPath); + } + +} + +UsdTextTextStyle +UsdTextTextStyleAPI::TextStyleBinding::GetTextStyle() const +{ + // Get the textstyle prim. + if (!_textStylePath.IsEmpty()) { + return UsdTextTextStyle(_bindingRel.GetStage()->GetPrimAtPath( + _textStylePath)); + } + return UsdTextTextStyle(); +} + +UsdTextTextStyleAPI::TextStyleBinding +UsdTextTextStyleAPI::GetTextStyleBinding(SdfPath const& primPath) const +{ + UsdRelationship bindingRel = GetBindingRel(); + return TextStyleBinding(bindingRel, primPath); +} + +bool +UsdTextTextStyleAPI::CanContainPropertyName(const TfToken &name) +{ + return TfStringStartsWith(name, UsdTextTokens->textStyleBinding); +} + +UsdRelationship +UsdTextTextStyleAPI::_CreateBindingRel() const +{ + return GetPrim().CreateRelationship(UsdTextTokens->textStyleBinding, /*custom*/ false); +} + + +bool +UsdTextTextStyleAPI::Bind(const UsdTextTextStyle &textStyle) const +{ + if (UsdRelationship bindingRel = _CreateBindingRel()) { + return bindingRel.SetTargets({ textStyle.GetPath() }); + } + + return false; +} + +UsdTextTextStyleAPI::TextStyleBindingCache UsdTextTextStyleAPI::_styleBindingCache; +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdText/textStyleAPI.h b/pxr/usd/usdText/textStyleAPI.h new file mode 100644 index 0000000000..5b7b35c57e --- /dev/null +++ b/pxr/usd/usdText/textStyleAPI.h @@ -0,0 +1,254 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDTEXT_GENERATED_TEXTSTYLEAPI_H +#define USDTEXT_GENERATED_TEXTSTYLEAPI_H + +/// \file usdText/textStyleAPI.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/usd/usd/apiSchemaBase.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdText/tokens.h" + +#include "pxr/usd/usdText/textStyle.h" +#include + + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// TEXTSTYLEAPI // +// -------------------------------------------------------------------------- // + +/// \class UsdTextTextStyleAPI +/// +/// UsdTextTextStyleAPI is an API schema that provides an interface for binding text style to a text +/// primitive. +/// +class UsdTextTextStyleAPI : public UsdAPISchemaBase +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI; + + /// Construct a UsdTextTextStyleAPI on UsdPrim \p prim . + /// Equivalent to UsdTextTextStyleAPI::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdTextTextStyleAPI(const UsdPrim& prim=UsdPrim()) + : UsdAPISchemaBase(prim) + { + } + + /// Construct a UsdTextTextStyleAPI on the prim held by \p schemaObj . + /// Should be preferred over UsdTextTextStyleAPI(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdTextTextStyleAPI(const UsdSchemaBase& schemaObj) + : UsdAPISchemaBase(schemaObj) + { + } + + /// Destructor. + USDTEXT_API + virtual ~UsdTextTextStyleAPI(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDTEXT_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdTextTextStyleAPI holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. This is shorthand for the following: + /// + /// \code + /// UsdTextTextStyleAPI(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDTEXT_API + static UsdTextTextStyleAPI + Get(const UsdStagePtr &stage, const SdfPath &path); + + + /// Returns true if this single-apply API schema can be applied to + /// the given \p prim. If this schema can not be a applied to the prim, + /// this returns false and, if provided, populates \p whyNot with the + /// reason it can not be applied. + /// + /// Note that if CanApply returns false, that does not necessarily imply + /// that calling Apply will fail. Callers are expected to call CanApply + /// before calling Apply if they want to ensure that it is valid to + /// apply a schema. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDTEXT_API + static bool + CanApply(const UsdPrim &prim, std::string *whyNot=nullptr); + + /// Applies this single-apply API schema to the given \p prim. + /// This information is stored by adding "TextStyleAPI" to the + /// token-valued, listOp metadata \em apiSchemas on the prim. + /// + /// \return A valid UsdTextTextStyleAPI object is returned upon success. + /// An invalid (or empty) UsdTextTextStyleAPI object is returned upon + /// failure. See \ref UsdPrim::ApplyAPI() for conditions + /// resulting in failure. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDTEXT_API + static UsdTextTextStyleAPI + Apply(const UsdPrim &prim); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDTEXT_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDTEXT_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDTEXT_API + const TfType &_GetTfType() const override; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- + using TextStyleBindingCache = + tbb::concurrent_unordered_multimap; + + /// Get the binding relatinship + USDTEXT_API + UsdRelationship + GetBindingRel() const; + + /// \class TextStyleBinding + /// This class represents binding to a textstyle. + class TextStyleBinding { + public: + /// Default constructor initializes a TextStyleBinding object with + /// invalid style and bindingRel data members. + TextStyleBinding() + {} + + /// Explicit constructor. + USDTEXT_API + explicit TextStyleBinding(const UsdRelationship &bindingRel, + SdfPath const& textPrimPath); + + /// Gets the textstyle prim that this binding binds to. + USDTEXT_API + UsdTextTextStyle GetTextStyle() const; + + /// Returns the path to the textstyle that is bound to by this + /// binding. + const SdfPath &GetTextStylePath() const { + return _textStylePath; + } + + /// Returns the binding-relationship that represents this binding. + const UsdRelationship &GetBindingRel() const { + return _bindingRel; + } + + private: + // The path to the textstyle that is bound to. + SdfPath _textStylePath; + + // The binding relationship. + UsdRelationship _bindingRel; + }; + + /// Get binding from the prim. + USDTEXT_API + TextStyleBinding + GetTextStyleBinding(SdfPath const& prim) const; + + /// Test whether a given \p name contains the "textStyle:" prefix + /// + USDTEXT_API + static bool CanContainPropertyName(const TfToken &name); + + /// Add a binding to a textstyle and the text prim to the cache. + USDTEXT_API + static bool AddBindToCache(SdfPath const& textStylePrimPath, + SdfPath const& textPrimPath) + { + _styleBindingCache.emplace(textStylePrimPath, textPrimPath); + return true; + } + + /// Find the text prims who have the binding to the specified textstyle. + USDTEXT_API + static bool FindBindedText(SdfPath const& textStylePrimPath, + std::pair& pathPair) + { + pathPair = _styleBindingCache.equal_range(textStylePrimPath); + if (pathPair.first != _styleBindingCache.end()) + return true; + else + return false; + } + + /// Bind a text style. + USDTEXT_API + bool Bind(const UsdTextTextStyle &textStyle) const; + +private: + UsdRelationship _CreateBindingRel() const; + + // A cache that save the map between textstyle and its binded text prim. + static TextStyleBindingCache _styleBindingCache; +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdText/tokens.cpp b/pxr/usd/usdText/tokens.cpp new file mode 100644 index 0000000000..c9216742d7 --- /dev/null +++ b/pxr/usd/usdText/tokens.cpp @@ -0,0 +1,103 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/tokens.h" + +PXR_NAMESPACE_OPEN_SCOPE + +UsdTextTokensType::UsdTextTokensType() : + bdf("bdf", TfToken::Immortal), + bottomToTop("bottomToTop", TfToken::Immortal), + charHeight("charHeight", TfToken::Immortal), + charSpacingFactor("charSpacingFactor", TfToken::Immortal), + charWidthFactor("charWidthFactor", TfToken::Immortal), + doubleLines("doubleLines", TfToken::Immortal), + fon("fon", TfToken::Immortal), + fontAltFormat("font:altFormat", TfToken::Immortal), + fontAltTypeface("font:altTypeface", TfToken::Immortal), + fontBold("font:bold", TfToken::Immortal), + fontFormat("font:format", TfToken::Immortal), + fontItalic("font:italic", TfToken::Immortal), + fontTypeface("font:typeface", TfToken::Immortal), + fontWeight("font:weight", TfToken::Immortal), + layoutBaselineDirection("layout:baselineDirection", TfToken::Immortal), + layoutLinesStackDirection("layout:linesStackDirection", TfToken::Immortal), + leftToRight("leftToRight", TfToken::Immortal), + none("none", TfToken::Immortal), + normal("normal", TfToken::Immortal), + obliqueAngle("obliqueAngle", TfToken::Immortal), + overlineType("overlineType", TfToken::Immortal), + pcf("pcf", TfToken::Immortal), + pfa_pfb("pfa/pfb", TfToken::Immortal), + pixel("pixel", TfToken::Immortal), + primvarsBackgroundColor("primvars:backgroundColor", TfToken::Immortal), + primvarsBackgroundOpacity("primvars:backgroundOpacity", TfToken::Immortal), + publishingPoint("publishingPoint", TfToken::Immortal), + rightToLeft("rightToLeft", TfToken::Immortal), + shx("shx", TfToken::Immortal), + strikethroughType("strikethroughType", TfToken::Immortal), + textData("textData", TfToken::Immortal), + textMetricsUnit("textMetricsUnit", TfToken::Immortal), + textStyleBinding("textStyle:binding", TfToken::Immortal), + topToBottom("topToBottom", TfToken::Immortal), + ttf_cff_otf("ttf/cff/otf", TfToken::Immortal), + underlineType("underlineType", TfToken::Immortal), + upToImpl("upToImpl", TfToken::Immortal), + worldUnit("worldUnit", TfToken::Immortal), + SimpleText("SimpleText", TfToken::Immortal), + TextLayoutAPI("TextLayoutAPI", TfToken::Immortal), + TextStyle("TextStyle", TfToken::Immortal), + TextStyleAPI("TextStyleAPI", TfToken::Immortal), + allTokens({ + bdf, + bottomToTop, + charHeight, + charSpacingFactor, + charWidthFactor, + doubleLines, + fon, + fontAltFormat, + fontAltTypeface, + fontBold, + fontFormat, + fontItalic, + fontTypeface, + fontWeight, + layoutBaselineDirection, + layoutLinesStackDirection, + leftToRight, + none, + normal, + obliqueAngle, + overlineType, + pcf, + pfa_pfb, + pixel, + primvarsBackgroundColor, + primvarsBackgroundOpacity, + publishingPoint, + rightToLeft, + shx, + strikethroughType, + textData, + textMetricsUnit, + textStyleBinding, + topToBottom, + ttf_cff_otf, + underlineType, + upToImpl, + worldUnit, + SimpleText, + TextLayoutAPI, + TextStyle, + TextStyleAPI + }) +{ +} + +TfStaticData UsdTextTokens; + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdText/tokens.h b/pxr/usd/usdText/tokens.h new file mode 100644 index 0000000000..dd16df0e16 --- /dev/null +++ b/pxr/usd/usdText/tokens.h @@ -0,0 +1,228 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDTEXT_TOKENS_H +#define USDTEXT_TOKENS_H + +/// \file usdText/tokens.h + +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +// +// This is an automatically generated file (by usdGenSchema.py). +// Do not hand-edit! +// +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/base/tf/staticData.h" +#include "pxr/base/tf/token.h" +#include + +PXR_NAMESPACE_OPEN_SCOPE + + +/// \class UsdTextTokensType +/// +/// \link UsdTextTokens \endlink provides static, efficient +/// \link TfToken TfTokens\endlink for use in all public USD API. +/// +/// These tokens are auto-generated from the module's schema, representing +/// property names, for when you need to fetch an attribute or relationship +/// directly by name, e.g. UsdPrim::GetAttribute(), in the most efficient +/// manner, and allow the compiler to verify that you spelled the name +/// correctly. +/// +/// UsdTextTokens also contains all of the \em allowedTokens values +/// declared for schema builtin attributes of 'token' scene description type. +/// Use UsdTextTokens like so: +/// +/// \code +/// gprim.GetMyTokenValuedAttr().Set(UsdTextTokens->bdf); +/// \endcode +struct UsdTextTokensType { + USDTEXT_API UsdTextTokensType(); + /// \brief "bdf" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr() + const TfToken bdf; + /// \brief "bottomToTop" + /// + /// Possible value for UsdTextTextLayoutAPI::GetLayoutBaselineDirectionAttr(), Possible value for UsdTextTextLayoutAPI::GetLayoutLinesStackDirectionAttr() + const TfToken bottomToTop; + /// \brief "charHeight" + /// + /// UsdTextTextStyle + const TfToken charHeight; + /// \brief "charSpacingFactor" + /// + /// UsdTextTextStyle + const TfToken charSpacingFactor; + /// \brief "charWidthFactor" + /// + /// UsdTextTextStyle + const TfToken charWidthFactor; + /// \brief "doubleLines" + /// + /// Possible value for UsdTextTextStyle::GetStrikethroughTypeAttr() + const TfToken doubleLines; + /// \brief "fon" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr() + const TfToken fon; + /// \brief "font:altFormat" + /// + /// UsdTextTextStyle + const TfToken fontAltFormat; + /// \brief "font:altTypeface" + /// + /// UsdTextTextStyle + const TfToken fontAltTypeface; + /// \brief "font:bold" + /// + /// UsdTextTextStyle + const TfToken fontBold; + /// \brief "font:format" + /// + /// UsdTextTextStyle + const TfToken fontFormat; + /// \brief "font:italic" + /// + /// UsdTextTextStyle + const TfToken fontItalic; + /// \brief "font:typeface" + /// + /// UsdTextTextStyle + const TfToken fontTypeface; + /// \brief "font:weight" + /// + /// UsdTextTextStyle + const TfToken fontWeight; + /// \brief "layout:baselineDirection" + /// + /// UsdTextTextLayoutAPI + const TfToken layoutBaselineDirection; + /// \brief "layout:linesStackDirection" + /// + /// UsdTextTextLayoutAPI + const TfToken layoutLinesStackDirection; + /// \brief "leftToRight" + /// + /// Possible value for UsdTextTextLayoutAPI::GetLayoutBaselineDirectionAttr(), Possible value for UsdTextTextLayoutAPI::GetLayoutLinesStackDirectionAttr() + const TfToken leftToRight; + /// \brief "none" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr(), Possible value for UsdTextTextStyle::GetOverlineTypeAttr(), Possible value for UsdTextTextStyle::GetStrikethroughTypeAttr(), Possible value for UsdTextTextStyle::GetUnderlineTypeAttr() + const TfToken none; + /// \brief "normal" + /// + /// Possible value for UsdTextTextStyle::GetOverlineTypeAttr(), Possible value for UsdTextTextStyle::GetStrikethroughTypeAttr(), Possible value for UsdTextTextStyle::GetUnderlineTypeAttr() + const TfToken normal; + /// \brief "obliqueAngle" + /// + /// UsdTextTextStyle + const TfToken obliqueAngle; + /// \brief "overlineType" + /// + /// UsdTextTextStyle + const TfToken overlineType; + /// \brief "pcf" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr() + const TfToken pcf; + /// \brief "pfa/pfb" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr() + const TfToken pfa_pfb; + /// \brief "pixel" + /// + /// Possible value for UsdTextSimpleText::GetTextMetricsUnitAttr() + const TfToken pixel; + /// \brief "primvars:backgroundColor" + /// + /// UsdTextSimpleText + const TfToken primvarsBackgroundColor; + /// \brief "primvars:backgroundOpacity" + /// + /// UsdTextSimpleText + const TfToken primvarsBackgroundOpacity; + /// \brief "publishingPoint" + /// + /// Possible value for UsdTextSimpleText::GetTextMetricsUnitAttr() + const TfToken publishingPoint; + /// \brief "rightToLeft" + /// + /// Possible value for UsdTextTextLayoutAPI::GetLayoutBaselineDirectionAttr(), Possible value for UsdTextTextLayoutAPI::GetLayoutLinesStackDirectionAttr() + const TfToken rightToLeft; + /// \brief "shx" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr() + const TfToken shx; + /// \brief "strikethroughType" + /// + /// UsdTextTextStyle + const TfToken strikethroughType; + /// \brief "textData" + /// + /// UsdTextSimpleText + const TfToken textData; + /// \brief "textMetricsUnit" + /// + /// UsdTextSimpleText + const TfToken textMetricsUnit; + /// \brief "textStyle:binding" + /// + /// The relationship name to denote a binding to a UsdTextTextStyle. + const TfToken textStyleBinding; + /// \brief "topToBottom" + /// + /// Possible value for UsdTextTextLayoutAPI::GetLayoutBaselineDirectionAttr(), Possible value for UsdTextTextLayoutAPI::GetLayoutLinesStackDirectionAttr() + const TfToken topToBottom; + /// \brief "ttf/cff/otf" + /// + /// Possible value for UsdTextTextStyle::GetFontAltFormatAttr(), Possible value for UsdTextTextStyle::GetFontFormatAttr() + const TfToken ttf_cff_otf; + /// \brief "underlineType" + /// + /// UsdTextTextStyle + const TfToken underlineType; + /// \brief "upToImpl" + /// + /// Fallback value for UsdTextTextLayoutAPI::GetLayoutBaselineDirectionAttr(), Fallback value for UsdTextTextLayoutAPI::GetLayoutLinesStackDirectionAttr() + const TfToken upToImpl; + /// \brief "worldUnit" + /// + /// Fallback value for UsdTextSimpleText::GetTextMetricsUnitAttr() + const TfToken worldUnit; + /// \brief "SimpleText" + /// + /// Schema identifer and family for UsdTextSimpleText + const TfToken SimpleText; + /// \brief "TextLayoutAPI" + /// + /// Schema identifer and family for UsdTextTextLayoutAPI + const TfToken TextLayoutAPI; + /// \brief "TextStyle" + /// + /// Schema identifer and family for UsdTextTextStyle + const TfToken TextStyle; + /// \brief "TextStyleAPI" + /// + /// Schema identifer and family for UsdTextTextStyleAPI + const TfToken TextStyleAPI; + /// A vector of all of the tokens listed above. + const std::vector allTokens; +}; + +/// \var UsdTextTokens +/// +/// A global variable with static, efficient \link TfToken TfTokens\endlink +/// for use in all public USD API. \sa UsdTextTokensType +extern USDTEXT_API TfStaticData UsdTextTokens; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdText/wrapSimpleText.cpp b/pxr/usd/usdText/wrapSimpleText.cpp new file mode 100644 index 0000000000..b88b33ba1d --- /dev/null +++ b/pxr/usd/usdText/wrapSimpleText.cpp @@ -0,0 +1,163 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/simpleText.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateTextDataAttr(UsdTextSimpleText &self, + object defaultVal, bool writeSparsely) { + return self.CreateTextDataAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateBackgroundColorAttr(UsdTextSimpleText &self, + object defaultVal, bool writeSparsely) { + return self.CreateBackgroundColorAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Color3f), writeSparsely); +} + +static UsdAttribute +_CreateBackgroundOpacityAttr(UsdTextSimpleText &self, + object defaultVal, bool writeSparsely) { + return self.CreateBackgroundOpacityAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateTextMetricsUnitAttr(UsdTextSimpleText &self, + object defaultVal, bool writeSparsely) { + return self.CreateTextMetricsUnitAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static std::string +_Repr(const UsdTextSimpleText &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdText.SimpleText(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapUsdTextSimpleText() +{ + typedef UsdTextSimpleText This; + + class_ > + cls("SimpleText"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetTextDataAttr", + &This::GetTextDataAttr) + .def("CreateTextDataAttr", + &_CreateTextDataAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetBackgroundColorAttr", + &This::GetBackgroundColorAttr) + .def("CreateBackgroundColorAttr", + &_CreateBackgroundColorAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetBackgroundOpacityAttr", + &This::GetBackgroundOpacityAttr) + .def("CreateBackgroundOpacityAttr", + &_CreateBackgroundOpacityAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetTextMetricsUnitAttr", + &This::GetTextMetricsUnitAttr) + .def("CreateTextMetricsUnitAttr", + &_CreateTextMetricsUnitAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usdText/wrapTextLayoutAPI.cpp b/pxr/usd/usdText/wrapTextLayoutAPI.cpp new file mode 100644 index 0000000000..475d202789 --- /dev/null +++ b/pxr/usd/usdText/wrapTextLayoutAPI.cpp @@ -0,0 +1,157 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/textLayoutAPI.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyAnnotatedBoolResult.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateLayoutBaselineDirectionAttr(UsdTextTextLayoutAPI &self, + object defaultVal, bool writeSparsely) { + return self.CreateLayoutBaselineDirectionAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static UsdAttribute +_CreateLayoutLinesStackDirectionAttr(UsdTextTextLayoutAPI &self, + object defaultVal, bool writeSparsely) { + return self.CreateLayoutLinesStackDirectionAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static std::string +_Repr(const UsdTextTextLayoutAPI &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdText.TextLayoutAPI(%s)", + primRepr.c_str()); +} + +struct UsdTextTextLayoutAPI_CanApplyResult : + public TfPyAnnotatedBoolResult +{ + UsdTextTextLayoutAPI_CanApplyResult(bool val, std::string const &msg) : + TfPyAnnotatedBoolResult(val, msg) {} +}; + +static UsdTextTextLayoutAPI_CanApplyResult +_WrapCanApply(const UsdPrim& prim) +{ + std::string whyNot; + bool result = UsdTextTextLayoutAPI::CanApply(prim, &whyNot); + return UsdTextTextLayoutAPI_CanApplyResult(result, whyNot); +} + +} // anonymous namespace + +void wrapUsdTextTextLayoutAPI() +{ + typedef UsdTextTextLayoutAPI This; + + UsdTextTextLayoutAPI_CanApplyResult::Wrap( + "_CanApplyResult", "whyNot"); + + class_ > + cls("TextLayoutAPI"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("CanApply", &_WrapCanApply, (arg("prim"))) + .staticmethod("CanApply") + + .def("Apply", &This::Apply, (arg("prim"))) + .staticmethod("Apply") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetLayoutBaselineDirectionAttr", + &This::GetLayoutBaselineDirectionAttr) + .def("CreateLayoutBaselineDirectionAttr", + &_CreateLayoutBaselineDirectionAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetLayoutLinesStackDirectionAttr", + &This::GetLayoutLinesStackDirectionAttr) + .def("CreateLayoutLinesStackDirectionAttr", + &_CreateLayoutLinesStackDirectionAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usdText/wrapTextStyle.cpp b/pxr/usd/usdText/wrapTextStyle.cpp new file mode 100644 index 0000000000..3fef3b19b4 --- /dev/null +++ b/pxr/usd/usdText/wrapTextStyle.cpp @@ -0,0 +1,303 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/textStyle.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateFontTypefaceAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontTypefaceAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateFontFormatAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontFormatAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateFontAltTypefaceAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontAltTypefaceAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateFontAltFormatAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontAltFormatAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateFontBoldAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontBoldAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely); +} + +static UsdAttribute +_CreateFontItalicAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontItalicAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely); +} + +static UsdAttribute +_CreateFontWeightAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateFontWeightAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateCharHeightAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateCharHeightAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely); +} + +static UsdAttribute +_CreateCharWidthFactorAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateCharWidthFactorAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateObliqueAngleAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateObliqueAngleAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateCharSpacingFactorAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateCharSpacingFactorAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateUnderlineTypeAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateUnderlineTypeAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateOverlineTypeAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateOverlineTypeAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateStrikethroughTypeAttr(UsdTextTextStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateStrikethroughTypeAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static std::string +_Repr(const UsdTextTextStyle &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdText.TextStyle(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapUsdTextTextStyle() +{ + typedef UsdTextTextStyle This; + + class_ > + cls("TextStyle"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetFontTypefaceAttr", + &This::GetFontTypefaceAttr) + .def("CreateFontTypefaceAttr", + &_CreateFontTypefaceAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetFontFormatAttr", + &This::GetFontFormatAttr) + .def("CreateFontFormatAttr", + &_CreateFontFormatAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetFontAltTypefaceAttr", + &This::GetFontAltTypefaceAttr) + .def("CreateFontAltTypefaceAttr", + &_CreateFontAltTypefaceAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetFontAltFormatAttr", + &This::GetFontAltFormatAttr) + .def("CreateFontAltFormatAttr", + &_CreateFontAltFormatAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetFontBoldAttr", + &This::GetFontBoldAttr) + .def("CreateFontBoldAttr", + &_CreateFontBoldAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetFontItalicAttr", + &This::GetFontItalicAttr) + .def("CreateFontItalicAttr", + &_CreateFontItalicAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetFontWeightAttr", + &This::GetFontWeightAttr) + .def("CreateFontWeightAttr", + &_CreateFontWeightAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetCharHeightAttr", + &This::GetCharHeightAttr) + .def("CreateCharHeightAttr", + &_CreateCharHeightAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetCharWidthFactorAttr", + &This::GetCharWidthFactorAttr) + .def("CreateCharWidthFactorAttr", + &_CreateCharWidthFactorAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetObliqueAngleAttr", + &This::GetObliqueAngleAttr) + .def("CreateObliqueAngleAttr", + &_CreateObliqueAngleAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetCharSpacingFactorAttr", + &This::GetCharSpacingFactorAttr) + .def("CreateCharSpacingFactorAttr", + &_CreateCharSpacingFactorAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetUnderlineTypeAttr", + &This::GetUnderlineTypeAttr) + .def("CreateUnderlineTypeAttr", + &_CreateUnderlineTypeAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOverlineTypeAttr", + &This::GetOverlineTypeAttr) + .def("CreateOverlineTypeAttr", + &_CreateOverlineTypeAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetStrikethroughTypeAttr", + &This::GetStrikethroughTypeAttr) + .def("CreateStrikethroughTypeAttr", + &_CreateStrikethroughTypeAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usdText/wrapTextStyleAPI.cpp b/pxr/usd/usdText/wrapTextStyleAPI.cpp new file mode 100644 index 0000000000..41129d74ab --- /dev/null +++ b/pxr/usd/usdText/wrapTextStyleAPI.cpp @@ -0,0 +1,139 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdText/textStyleAPI.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyAnnotatedBoolResult.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static std::string +_Repr(const UsdTextTextStyleAPI &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdText.TextStyleAPI(%s)", + primRepr.c_str()); +} + +struct UsdTextTextStyleAPI_CanApplyResult : + public TfPyAnnotatedBoolResult +{ + UsdTextTextStyleAPI_CanApplyResult(bool val, std::string const &msg) : + TfPyAnnotatedBoolResult(val, msg) {} +}; + +static UsdTextTextStyleAPI_CanApplyResult +_WrapCanApply(const UsdPrim& prim) +{ + std::string whyNot; + bool result = UsdTextTextStyleAPI::CanApply(prim, &whyNot); + return UsdTextTextStyleAPI_CanApplyResult(result, whyNot); +} + +} // anonymous namespace + +void wrapUsdTextTextStyleAPI() +{ + typedef UsdTextTextStyleAPI This; + + UsdTextTextStyleAPI_CanApplyResult::Wrap( + "_CanApplyResult", "whyNot"); + + class_ > + cls("TextStyleAPI"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("CanApply", &_WrapCanApply, (arg("prim"))) + .staticmethod("CanApply") + + .def("Apply", &This::Apply, (arg("prim"))) + .staticmethod("Apply") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def("GetTextStyleBinding", + &This::GetTextStyleBinding, + arg("primPath")) + + .def(!self) + + + .def("__repr__", ::_Repr) + ; + + class_ textStyleBinding("TextStyleBinding"); + textStyleBinding + .def(init<>()) + .def("GetTextStyle", &This::TextStyleBinding::GetTextStyle) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usdText/wrapTokens.cpp b/pxr/usd/usdText/wrapTokens.cpp new file mode 100644 index 0000000000..85d3146026 --- /dev/null +++ b/pxr/usd/usdText/wrapTokens.cpp @@ -0,0 +1,92 @@ +// +// Copyright 2024 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +// GENERATED FILE. DO NOT EDIT. +#include +#include "pxr/usd/usdText/tokens.h" + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +// Helper to return a static token as a string. We wrap tokens as Python +// strings and for some reason simply wrapping the token using def_readonly +// bypasses to-Python conversion, leading to the error that there's no +// Python type for the C++ TfToken type. So we wrap this functor instead. +class _WrapStaticToken { +public: + _WrapStaticToken(const TfToken* token) : _token(token) { } + + std::string operator()() const + { + return _token->GetString(); + } + +private: + const TfToken* _token; +}; + +template +void +_AddToken(T& cls, const char* name, const TfToken& token) +{ + cls.add_static_property(name, + boost::python::make_function( + _WrapStaticToken(&token), + boost::python::return_value_policy< + boost::python::return_by_value>(), + boost::mpl::vector1())); +} + +} // anonymous + +void wrapUsdTextTokens() +{ + boost::python::class_ + cls("Tokens", boost::python::no_init); + _AddToken(cls, "bdf", UsdTextTokens->bdf); + _AddToken(cls, "bottomToTop", UsdTextTokens->bottomToTop); + _AddToken(cls, "charHeight", UsdTextTokens->charHeight); + _AddToken(cls, "charSpacingFactor", UsdTextTokens->charSpacingFactor); + _AddToken(cls, "charWidthFactor", UsdTextTokens->charWidthFactor); + _AddToken(cls, "doubleLines", UsdTextTokens->doubleLines); + _AddToken(cls, "fon", UsdTextTokens->fon); + _AddToken(cls, "fontAltFormat", UsdTextTokens->fontAltFormat); + _AddToken(cls, "fontAltTypeface", UsdTextTokens->fontAltTypeface); + _AddToken(cls, "fontBold", UsdTextTokens->fontBold); + _AddToken(cls, "fontFormat", UsdTextTokens->fontFormat); + _AddToken(cls, "fontItalic", UsdTextTokens->fontItalic); + _AddToken(cls, "fontTypeface", UsdTextTokens->fontTypeface); + _AddToken(cls, "fontWeight", UsdTextTokens->fontWeight); + _AddToken(cls, "layoutBaselineDirection", UsdTextTokens->layoutBaselineDirection); + _AddToken(cls, "layoutLinesStackDirection", UsdTextTokens->layoutLinesStackDirection); + _AddToken(cls, "leftToRight", UsdTextTokens->leftToRight); + _AddToken(cls, "none", UsdTextTokens->none); + _AddToken(cls, "normal", UsdTextTokens->normal); + _AddToken(cls, "obliqueAngle", UsdTextTokens->obliqueAngle); + _AddToken(cls, "overlineType", UsdTextTokens->overlineType); + _AddToken(cls, "pcf", UsdTextTokens->pcf); + _AddToken(cls, "pfa_pfb", UsdTextTokens->pfa_pfb); + _AddToken(cls, "pixel", UsdTextTokens->pixel); + _AddToken(cls, "primvarsBackgroundColor", UsdTextTokens->primvarsBackgroundColor); + _AddToken(cls, "primvarsBackgroundOpacity", UsdTextTokens->primvarsBackgroundOpacity); + _AddToken(cls, "publishingPoint", UsdTextTokens->publishingPoint); + _AddToken(cls, "rightToLeft", UsdTextTokens->rightToLeft); + _AddToken(cls, "shx", UsdTextTokens->shx); + _AddToken(cls, "strikethroughType", UsdTextTokens->strikethroughType); + _AddToken(cls, "textData", UsdTextTokens->textData); + _AddToken(cls, "textMetricsUnit", UsdTextTokens->textMetricsUnit); + _AddToken(cls, "textStyleBinding", UsdTextTokens->textStyleBinding); + _AddToken(cls, "topToBottom", UsdTextTokens->topToBottom); + _AddToken(cls, "ttf_cff_otf", UsdTextTokens->ttf_cff_otf); + _AddToken(cls, "underlineType", UsdTextTokens->underlineType); + _AddToken(cls, "upToImpl", UsdTextTokens->upToImpl); + _AddToken(cls, "worldUnit", UsdTextTokens->worldUnit); + _AddToken(cls, "SimpleText", UsdTextTokens->SimpleText); + _AddToken(cls, "TextLayoutAPI", UsdTextTokens->TextLayoutAPI); + _AddToken(cls, "TextStyle", UsdTextTokens->TextStyle); + _AddToken(cls, "TextStyleAPI", UsdTextTokens->TextStyleAPI); +}