| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- //
- // Copyright (c) 2008-2017 the Urho3D project.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "../../Container/ArrayPtr.h"
- #include "../../Container/List.h"
- #include "../../Math/AreaAllocator.h"
- namespace Atomic
- {
- class Text3DFont;
- class Image;
- class Texture2D;
- /// %Font glyph description.
- struct ATOMIC_API Text3DFontGlyph
- {
- /// Construct.
- Text3DFontGlyph();
- /// X position in texture.
- short x_;
- /// Y position in texture.
- short y_;
- /// Width.
- short width_;
- /// Height.
- short height_;
- /// Glyph X offset from origin.
- short offsetX_;
- /// Glyph Y offset from origin.
- short offsetY_;
- /// Horizontal advance.
- float advanceX_;
- /// Texture page. M_MAX_UNSIGNED if not yet resident on any texture.
- unsigned page_;
- /// Used flag.
- bool used_;
- };
- /// %Font face description.
- class ATOMIC_API Text3DFontFace : public RefCounted
- {
- friend class Text3DFont;
- ATOMIC_REFCOUNTED(FontFace)
- public:
- /// Construct.
- Text3DFontFace(Text3DFont* font);
- /// Destruct.
- ~Text3DFontFace();
- /// Load font face.
- virtual bool Load(const unsigned char* fontData, unsigned fontDataSize, float pointSize) = 0;
- /// Return pointer to the glyph structure corresponding to a character. Return null if glyph not found.
- virtual const Text3DFontGlyph* GetGlyph(unsigned c);
- /// Return if font face uses mutable glyphs.
- virtual bool HasMutableGlyphs() const { return false; }
- /// Return the kerning for a character and the next character.
- float GetKerning(unsigned c, unsigned d) const;
- /// Return true when one of the texture has a data loss.
- bool IsDataLost() const;
- /// Return point size.
- float GetPointSize() const { return pointSize_; }
- /// Return row height.
- float GetRowHeight() const { return rowHeight_; }
- /// Return textures.
- const Vector<SharedPtr<Texture2D> >& GetTextures() const { return textures_; }
- protected:
- friend class Text3DBitmap;
- /// Create a texture for font rendering.
- SharedPtr<Texture2D> CreateFaceTexture();
- /// Load font face texture from image resource.
- SharedPtr<Texture2D> LoadFaceTexture(SharedPtr<Image> image);
- /// Parent font.
- Text3DFont* font_;
- /// Glyph mapping.
- HashMap<unsigned, Text3DFontGlyph> glyphMapping_;
- /// Kerning mapping.
- HashMap<unsigned, float> kerningMapping_;
- /// Glyph texture pages.
- Vector<SharedPtr<Texture2D> > textures_;
- /// Point size.
- float pointSize_;
- /// Row height.
- float rowHeight_;
- };
- }
|