<commit_before>/*****************************************************************************

-CLASS-
SVG: Provides support for parsing and rendering SVG files.

The SVG class provides support for parsing SVG statements into native @Vector objects and related definitions.
For low-level vector programming, consider using the @Vector class directly, or use the SVG class to parse an
SVG script and then access the #Viewport field to perform transforms and manipulation of the vector group.

Please refer to the W3C documentation on SVG for a complete reference to the attributes that can be applied to SVG
elements.  Unfortunately we do not support all SVG capabilities at this time, but support will improve in future.

*****************************************************************************/

/*****************************************************************************
-ACTION-
Activate: Initiates playback of SVG animations.
-END-
*****************************************************************************/

static ERROR SVG_Activate(objSVG *Self, APTR Void)
{
   if (Self->Animated) {
      if (!Self->AnimationTimer) {
         FUNCTION timer;
         SET_FUNCTION_STDC(timer, animation_timer);
         SubscribeTimer(1.0 / (DOUBLE)Self->FrameRate, &timer, &Self->AnimationTimer);
      }
      else UpdateTimer(Self->AnimationTimer, 1.0 / (DOUBLE)Self->FrameRate);
   }

   return ERR_Okay;
}

/*****************************************************************************
-ACTION-
Deactivate: Stops all playback of SVG animations.
-END-
*****************************************************************************/

static ERROR SVG_Deactivate(objSVG *Self, APTR Void)
{
   if (Self->AnimationTimer) { UpdateTimer(Self->AnimationTimer, 0); Self->AnimationTimer = 0; }
   return ERR_Okay;
}

/*****************************************************************************
-ACTION-
DataFeed: Vector graphics are created by passing XML-based instructions here.
-END-
*****************************************************************************/

static ERROR SVG_DataFeed(objSVG *Self, struct acDataFeed *Args)
{
   if (!Args) return ERR_NullArgs;

   if (Args->DataType IS DATA_XML) {
      return load_svg(Self, NULL, Args->Buffer);
   }

   return ERR_Okay;
}

//****************************************************************************

static ERROR SVG_Free(objSVG *Self, APTR Void)
{
   if (Self->AnimationTimer) {
      UpdateTimer(Self->AnimationTimer, 0);
      Self->AnimationTimer = 0;
   }

   if ((Self->Target) AND (Self->Target IS &Self->Scene->Head) AND (Self->Scene->Head.OwnerID IS Self->Head.UniqueID)) {
      acFree(Self->Target);
      Self->Target = NULL;
   }

   if (Self->Path)  { FreeResource(Self->Path);  Self->Path = NULL; }
   if (Self->Title) { FreeResource(Self->Title); Self->Title = NULL; }

   struct svgAnimation *anim = Self->Animations;
   while (anim) {
      struct svgAnimation *next = anim->Next;
      LONG i;
      for (i=0; i < anim->ValueCount; i++) {
         FreeResource(anim->Values[i]);
         anim->Values[i] = NULL;
      }
      FreeResource(anim);
      anim = next;
   }
   Self->Animations = NULL;

   svgID *symbol = Self->IDs;
   while (symbol) {
      svgID *next = symbol->Next;
      if (symbol->ID) { FreeResource(symbol->ID); symbol->ID = NULL; }
      FreeResource(symbol);
      symbol = next;
   }
   Self->IDs = NULL;

   svgInherit *inherit = Self->Inherit;
   while (inherit) {
      svgInherit *next = inherit->Next;
      FreeResource(inherit);
      inherit = next;
   }
   Self->Inherit = NULL;

   return ERR_Okay;
}

//****************************************************************************
<commit_msg>Documented the SVG Init action<commit_after>/*****************************************************************************

-CLASS-
SVG: Provides support for parsing and rendering SVG files.

The SVG class provides support for parsing SVG statements into native @Vector objects and related definitions.
For low-level vector programming, consider using the @Vector class directly, or use the SVG class to parse an
SVG script and then access the #Viewport field to perform transforms and manipulation of the vector group.

Please refer to the W3C documentation on SVG for a complete reference to the attributes that can be applied to SVG
elements.  Unfortunately we do not support all SVG capabilities at this time, but support will improve in future.

*****************************************************************************/

/*****************************************************************************
-ACTION-
Activate: Initiates playback of SVG animations.
-END-
*****************************************************************************/

static ERROR SVG_Activate(objSVG *Self, APTR Void)
{
   if (Self->Animated) {
      if (!Self->AnimationTimer) {
         FUNCTION timer;
         SET_FUNCTION_STDC(timer, animation_timer);
         SubscribeTimer(1.0 / (DOUBLE)Self->FrameRate, &timer, &Self->AnimationTimer);
      }
      else UpdateTimer(Self->AnimationTimer, 1.0 / (DOUBLE)Self->FrameRate);
   }

   return ERR_Okay;
}

/*****************************************************************************
-ACTION-
Deactivate: Stops all playback of SVG animations.
-END-
*****************************************************************************/

static ERROR SVG_Deactivate(objSVG *Self, APTR Void)
{
   if (Self->AnimationTimer) { UpdateTimer(Self->AnimationTimer, 0); Self->AnimationTimer = 0; }
   return ERR_Okay;
}

/*****************************************************************************
-ACTION-
DataFeed: Vector graphics are created by passing XML-based instructions here.
-END-
*****************************************************************************/

static ERROR SVG_DataFeed(objSVG *Self, struct acDataFeed *Args)
{
   if (!Args) return ERR_NullArgs;

   if (Args->DataType IS DATA_XML) {
      return load_svg(Self, NULL, Args->Buffer);
   }

   return ERR_Okay;
}

//****************************************************************************

static ERROR SVG_Free(objSVG *Self, APTR Void)
{
   if (Self->AnimationTimer) {
      UpdateTimer(Self->AnimationTimer, 0);
      Self->AnimationTimer = 0;
   }

   if ((Self->Target) AND (Self->Target IS &Self->Scene->Head) AND (Self->Scene->Head.OwnerID IS Self->Head.UniqueID)) {
      acFree(Self->Target);
      Self->Target = NULL;
   }

   if (Self->Path)  { FreeResource(Self->Path);  Self->Path = NULL; }
   if (Self->Title) { FreeResource(Self->Title); Self->Title = NULL; }

   struct svgAnimation *anim = Self->Animations;
   while (anim) {
      struct svgAnimation *next = anim->Next;
      LONG i;
      for (i=0; i < anim->ValueCount; i++) {
         FreeResource(anim->Values[i]);
         anim->Values[i] = NULL;
      }
      FreeResource(anim);
      anim = next;
   }
   Self->Animations = NULL;

   svgID *symbol = Self->IDs;
   while (symbol) {
      svgID *next = symbol->Next;
      if (symbol->ID) { FreeResource(symbol->ID); symbol->ID = NULL; }
      FreeResource(symbol);
      symbol = next;
   }
   Self->IDs = NULL;

   svgInherit *inherit = Self->Inherit;
   while (inherit) {
      svgInherit *next = inherit->Next;
      FreeResource(inherit);
      inherit = next;
   }
   Self->Inherit = NULL;

   return ERR_Okay;
}

/*****************************************************************************
-ACTION-
Init: Initialise the SVG object.

Initialising an SVG object will load an SVG source file if a #Path has been specified.  The default behaviour is to
generate the content in a local #Scene object, or alternatively the content can be redirected to an external
@VectorScene referred to by #Target.

-END-
*****************************************************************************/

{'fraction_non_alphanumeric': 0.2967552376085846, 'fraction_numerical': 0.0025549310168625446, 'mean_word_length': 4.243804420629605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4011543', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1958, 'n_words': 619}