diff --git a/src/Wellspring.c b/src/Wellspring.c index 5e38770..b3c9f38 100644 --- a/src/Wellspring.c +++ b/src/Wellspring.c @@ -226,11 +226,14 @@ static uint8_t json_object_has_key(const json_object_t *object, const char* name while (SDL_strcmp(currentName, name) != 0) { - if (currentElement->next != NULL) + if (currentElement->next == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Key %s not found in JSON!", name); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Key %s not found in JSON!", name); return 0; } + + currentElement = currentElement->next; + currentName = currentElement->name->string; } return 1; @@ -243,9 +246,9 @@ static json_object_element_t* json_object_get_element_by_name(const json_object_ while (SDL_strcmp(currentName, name) != 0) { - if (currentElement->next != NULL) + if (currentElement->next == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Key %s not found in JSON!", name); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Key %s not found in JSON!", name); return NULL; } @@ -269,7 +272,7 @@ static json_object_t* json_object_get_object(const json_object_t *object, const if (obj == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not an object!", name); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not an object!", name); } return obj; @@ -288,7 +291,7 @@ static const char* json_object_get_string(const json_object_t *object, const cha if (str == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not a string!", name); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not a string!", name); return NULL; } @@ -308,7 +311,7 @@ static uint32_t json_object_get_uint(const json_object_t *object, const char* na if (num == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not a number!", name); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not a number!", name); return 0; } @@ -328,7 +331,7 @@ static double json_object_get_double(const json_object_t *object, const char* na if (num == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Value with key %s was not a string!", name); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Value with key %s was not a string!", name); return 0; } @@ -361,7 +364,7 @@ Wellspring_Font* Wellspring_CreateFont( if (jsonObject == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Atlas JSON is invalid! Bailing!"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Atlas JSON is invalid! Bailing!"); Wellspring_free(font->fontBytes); Wellspring_free(font); return NULL; @@ -369,7 +372,7 @@ Wellspring_Font* Wellspring_CreateFont( if (SDL_strcmp(jsonObject->start->name->string, "atlas") != 0) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Atlas JSON is invalid! Bailing!"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Atlas JSON is invalid! Bailing!"); Wellspring_free(jsonRoot); Wellspring_free(font->fontBytes); Wellspring_free(font); @@ -384,7 +387,7 @@ Wellspring_Font* Wellspring_CreateFont( if (SDL_strcmp(atlasType, "msdf") != 0) { - SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Atlas is not MSDF! Bailing!"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Atlas is not MSDF! Bailing!"); Wellspring_free(jsonRoot); Wellspring_free(font->fontBytes); Wellspring_free(font); @@ -422,7 +425,7 @@ Wellspring_Font* Wellspring_CreateFont( // first codepoint on first range font->packer.ranges[charRangeIndex].firstCodepoint = codepoint; } - else if (codepoint != font->packer.ranges[charRangeIndex].firstCodepoint + font->packer.ranges[charRangeIndex].charCount + 1) + else if (codepoint != font->packer.ranges[charRangeIndex].firstCodepoint + font->packer.ranges[charRangeIndex].charCount) { // codepoint is not continuous, start a new range charRangeIndex += 1; @@ -436,6 +439,15 @@ Wellspring_Font* Wellspring_CreateFont( font->packer.ranges[charRangeIndex].data = Wellspring_realloc(font->packer.ranges[charRangeIndex].data, sizeof(PackedChar) * font->packer.ranges[charRangeIndex].charCount); PackedChar *packedChar = &font->packer.ranges[charRangeIndex].data[font->packer.ranges[charRangeIndex].charCount - 1]; + packedChar->atlasLeft = 0; + packedChar->atlasRight = 0; + packedChar->atlasTop = 0; + packedChar->atlasBottom = 0; + packedChar->planeLeft = 0; + packedChar->planeRight = 0; + packedChar->planeTop = 0; + packedChar->planeBottom = 0; + packedChar->xAdvance = json_object_get_double(currentGlyphObject, "advance"); if (json_object_has_key(currentGlyphObject, "atlasBounds"))