@@ -117,17 +117,16 @@ const char* heif_text_item_get_content(heif_text_item* text_item)
117117 return text_c;
118118}
119119
120- struct heif_error heif_item_get_property_extended_language (const heif_context* context,
121- heif_item_id itemId,
122- char ** out_language)
120+
121+ heif_error heif_text_item_get_property_extended_language (const heif_text_item* text_item, char ** out_language)
123122{
124- if (!out_language || !context ) {
123+ if (!out_language || !text_item ) {
125124 return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, " NULL passed" };
126125 }
127126
128- auto elng = context ->context ->find_property <Box_elng>(itemId );
127+ auto elng = text_item ->context ->find_property <Box_elng>(text_item-> text_item -> get_item_id () );
129128 if (!elng) {
130- return elng.error_struct (context ->context .get ());
129+ return elng.error_struct (text_item ->context .get ());
131130 }
132131
133132 std::string lang = (*elng)->get_extended_language ();
@@ -137,27 +136,22 @@ struct heif_error heif_item_get_property_extended_language(const heif_context* c
137136 return heif_error_success;
138137}
139138
140- struct heif_error heif_text_item_set_extended_language (heif_text_item* text_item, const char *language, heif_property_id* out_optional_propertyId)
139+
140+ heif_error heif_text_item_set_extended_language (heif_text_item* text_item, const char *language, heif_property_id* out_optional_propertyId)
141141{
142142 if (!text_item || !language) {
143143 return {heif_error_Usage_error, heif_suberror_Null_pointer_argument, " NULL passed" };
144144 }
145145
146- if (auto img = text_item->context ->get_image (text_item->text_item ->get_item_id (), false )) {
147- auto existing_elng = img->get_property <Box_elng>();
148- if (existing_elng) {
149- existing_elng->set_lang (std::string (language));
150- return heif_error_success;
151- }
152- }
146+ Result<heif_property_id> property_id_result = text_item->context ->add_text_property (text_item->text_item ->get_item_id (),
147+ language);
153148
154- auto elng = std::make_shared<Box_elng>();
155- elng->set_lang (std::string (language));
156-
157- heif_property_id id = text_item->context ->add_property (text_item->text_item ->get_item_id (), elng, false );
149+ if (auto err = property_id_result.error ()) {
150+ return err.error_struct (text_item->context .get ());
151+ }
158152
159153 if (out_optional_propertyId) {
160- *out_optional_propertyId = id ;
154+ *out_optional_propertyId = *property_id_result ;
161155 }
162156
163157 return heif_error_success;
0 commit comments