Resolved long word break fit

This commit is contained in:
Lorenzo Iovino 2017-03-14 18:33:01 +01:00
parent 7b51b80e91
commit 9d15ae732f
2 changed files with 6 additions and 4 deletions

View file

@ -70,7 +70,6 @@ For sure is not a good implementation, maybe is not the best way to do it, but,
### Todos
- Write tests
- Resolve the problem with long word checking the overflowY
- Find a better algorithm to find the font-size who fits better the container
License

View file

@ -14,8 +14,8 @@ export class FittextDirective implements AfterViewInit {
constructor(public el: ElementRef, public renderer: Renderer) {
}
checkOverflowX(parent:any, children:any) {
return children.clientHeight > parent.clientHeight;
checkOverflow(parent:any, children:any) {
return (children.clientHeight > parent.clientHeight || children.scrollWidth > parent.clientWidth);
}
@HostListener('window:resize', ['$event'])
@ -32,8 +32,11 @@ export class FittextDirective implements AfterViewInit {
this.fontSize = this.container.clientWidth;
this.el.nativeElement.style.setProperty('font-size', (this.fontSize).toString()+'px');
}
let overflow = this.checkOverflowX(this.container, this.el.nativeElement);
let overflow = this.checkOverflow(this.container, this.el.nativeElement);
if(overflow) {
if(this.fontSize < 2) {
return;
}
this.fontSize = Math.floor(this.fontSize/this.speed);
this.el.nativeElement.style.setProperty('font-size', (this.fontSize).toString()+'px');
this.ngAfterViewInit();